[Numpy-discussion] create an object array with named dtype
Skipper Seabold
jsseabold@gmail....
Thu Nov 4 11:08:43 CDT 2010
I just ran into this and am kind of baffled. There are other ways I
could do this so it's not a huge deal, but I'm wondering if this is a
bug. I want a (named) structured array with an object dtype. Is this
possible?
For example
In [68]: import numpy as np
In [69]: A = np.array((np.arange(10)[:,None], 3, 4.5), dtype=[("prob", float, (1
0,1)),
....: ("m1", float),("m2", float)])
In [70]: B = np.array((np.arange(10,20)[:,None], 3, 4.5), dtype=[("prob", float,
(10,1)),
....: ("m1", float),("m2", float)])
This works fine.
In [71]: C = np.empty(2, dtype=object)
In [72]: C[0] = A
In [73]: C[1] = B
In [74]: np.all(C[0] == A)
Out[74]: True
In [75]: np.all(C[1] == B)
Out[75]: True
This doesn't. Looks like it takes a bad view on the array part (?)
In [76]: D = np.empty(2, dtype=[("n1",object),("n2", object)])
In [77]: D["n1"] = A
In [78]: D["n2"] = B
In [79]: np.all(D["n1"] == A)
Out[79]: False
In [80]: np.all(D["n2"] == B)
Out[80]: False
Skipper
More information about the NumPy-Discussion
mailing list