0

I have a section of code that I am using to calculate magnetic fields and magnetic vector potentials. I do various things to calculate an inverse curl, but I'm getting stuck on a namespace issue in python and I'm not sure how to move forward.

The code (shortened a little) works like this

def main():
    # define all my arrays 
    Ax = np.zeros(nx)
    # call a function to update a particular component of the Ax 
    index = 50
    update_A(Ax[index])
    return Ax 

def update_A(Axmm):
   # do a calculation to get this new component
   Axmm = some function

The update_A function is calculating the value as expected, but then isn't overwriting the element of Ax like I want it to. How can I get it to do the calculation and update the element of Ax that I've given it?

1
  • 2
    Ax[index] = calc_ new_A(Ax[index]) most types in python are immutable, so you pass to function not "array cell", but just copy of array element and assignment has no effect to array Commented Mar 11, 2021 at 11:09

1 Answer 1

1
#Pass and Index to your update function.

def update_A(Axmm, index):
   # do a calculation to get this new component
   Axmm[index] = some function

#Let me know if that's not working the way you meant.
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.