2

I am trying to call a method multiple times with the use of a for loop but change the value of a variable (i) that will be passed into the method (method1) on every iteration. I planned to do this within a for loop but keep getting the error:

TypeError: 'numpy.ndarray' object is not callable

I have looked at other similar issues but none seem to resolve my issue or provide a way to still call the method in the way I desire.

array = np.array([1, 63, 96, 122, 35, 52, 67, 0.01])

for i in array:
    result = method1(collection, data, i)
    method1= price.dot(result)

Any help with this would be much appriciated!

2
  • 2
    Is method1 really a function? Might it be a numpy array (by mistake)? Or does the error occur inside method1? You might need to show the full error and traceback. Commented Mar 11, 2019 at 21:29
  • Yes this was the cause of my error I have expanded the example code to make it clear Commented Mar 11, 2019 at 21:34

2 Answers 2

1

In your for loop when you assign method1 = price.dot(result) method1 is now a numpy.ndarray and on the next iteration of the loop it is not callable anymore

Sign up to request clarification or add additional context in comments.

Comments

0

You should be able to loop through numpy array with that. Just wondering you don't have a space between 'method' and '1' in your code, do you? Because there shouldn't be a space there...

1 Comment

Thanks for the reply, that was a typo from formatting my question and not in my code, I have now changed it.

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.