Suppose I have defined a datatype, as below:
class mytype(object):
def __init__(self, x=1, y=2, z=3):
self.x = x
self.y = y
self.z = z
And I have an numpy array of type mytype, which is defined as:
my_array = np.array([mytype()]*1000)
And my question is: how to extract the values of the numpy array defined above and set it to an numpy array of type np.float64 more efficiently? I have found using list comprehension is very slow when the array is large, and I guess there must be some good way to do this job. Can anyone help me out
objectsare lttle better, maybe worse, than a list.[mytype()]*1000)makes a list with 1000 references to the same object. Try modifying one to see what I mean.