I have a multi-dimensional array of objects. I want to interate over the objects using the nditer iterator. Here is a code example:
import numpy as np
class Test:
def __init__(self,a):
self.a = a
def get_a(self):
return self.a
b = np.empty((2,3),dtype = object)
t_00 = Test(0)
t_01 = Test(1)
t_11 = Test (11)
b[0,0] = t_00
b[0,1] = t_01
b[1,1] = t_11
for item in np.nditer(b,flags = ["refs_ok"]):
if item:
print item.get_a()
I would expect the "item" to contain the object reference that I can use to access data. However I am getting the following error:AttributeError: 'numpy.ndarray' object has no attribute 'get_a' My question is how can I go thru the array to access the object in the array?