Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7933407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:19:27+00:00 2026-06-03T21:19:27+00:00

I have a python function func(A) . A is a numpy.array and can be

  • 0

I have a python function func(A). A is a numpy.array and can be big such that I hesitate copying it over and over again. This func(A) wants to change the content of A. I know this a python newbie issue. I used to program in C and it could be done by pointers. How can I change the content of A so that the change is also valid outside the scope of the func(A)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:19:28+00:00Added an answer on June 3, 2026 at 9:19 pm

    The tl;dr is in your case, it basically already is. Unless you assign a new value to the label A in the method, A will be a reference to the object you passed, which means any modifications to A will change the original object everywhere else you use it.

    ex:

    >>> def foo(A):
    ...     print A[0]
    ...     A[0] = 2
    ...     print A[0]
    ...
    >>> a = [0, 1, 2]
    >>> foo(a)
    0
    2
    >>> a
    [2, 1, 2]
    >>> def bar(A):
    ...     print A[0]
    ...     A = [0, 1, 2]
    ...     A[0] = 2
    ...     print A[0]
    ...
    >>> a = [0, 1, 2]
    >>> bar(a)
    0
    2
    >>> a
    [0, 1, 2]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a large in memory numpy array, I have a function func
I have a python function that makes a subprocess call to a shell script
I have a python function that randomize a dictionary representing a position specific scoring
I have this function in Python: def Rotate_Vector(vector, axis, direction): where vector is a
I am working with datetime objects in python. I have a function that takes
I have a python function that contains an if-statement to check something. def my_func(a,
I have a python script that I run with 'exec'. When a function is
Say I have a Python function that returns multiple values in a tuple: def
I have a Python function that takes a list as a parameter. If I
I have a python function that may raise an exception. The caller catches the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.