简体   繁体   中英

TypeError: 'numpy.ndarray' object is not callable within for loop Python

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!

在你的 for 循环中,当你分配method1 = price.dot(result) method1 现在是一个numpy.ndarray并且在循环的下一次迭代中它不再是可调用的

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM