[Numpy-discussion] Possible conversion bug with record array
Chris Barker - NOAA Federal
chris.barker at noaa.gov
Wed May 22 13:39:37 EDT 2013
On Wed, May 22, 2013 at 10:07 AM, Nicolas Rougier
> U = np.zeros(1, dtype=[('x', np.float32, (4,4))])
>
> U[0] = np.eye(4)
> print U[0]
> # output: ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)
I get the same thing. Note:
In [86]: U[0].shape
Out[86]: ()
it's a rank-zero array, not a 4X4 array -- some odd tings can happen there...
This works:
In [94]: U = np.zeros(1, dtype=[('x', np.float32, (4,4))])
In [95]: U['x'][0] = np.eye(4)
In [96]: U
Out[96]:
array([ ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0,
0.0], [0.0, 0.0, 0.0, 1.0]],)],
dtype=[('x', '<f4', (4, 4))])
Not that the first version isn't a bug!
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the NumPy-Discussion
mailing list