I have such a class
class Point:
def __init__(self, x,y,z):
self.x = x
self.y = y
self.z = z
where x,y,z are float
and I want to do this:
p = Point(0,0,0)
arr_p = np.array(p)
arr_pts = np.array([p])
what I expect:
>>> arr_p
array([0., 0., 0.])
>>> arr_pts
array([[0., 0., 0.]])
and both have dtype=np.float64
How can I customize my class to achieve this?
What I've tried: I saw some comments in numpy.array
object : array_like
An array, any object exposing the array interface, an object whose
__array__ method returns an array, or any (nested) sequence.
so I simply added
def __array__(self):
return [self.x, self.y, self.z]
But it doesn't work....I don't know what does it mean by array, is it C level thing that we need to manage the memory layout?
p? A list ofPointinstances? Be clear.