[Numpy-discussion] field names on numpy arrays
Pierre GM
pgmdevlist at gmail.com
Wed Jun 3 19:33:05 EDT 2009
On Jun 3, 2009, at 7:23 PM, Robert Kern wrote:
> On Wed, Jun 3, 2009 at 18:20, Pierre GM <pgmdevlist at gmail.com> wrote:
>>
>>
>> Or, as all fields have the same dtype:
>>
>> >>> a_array.view(dtype=('f',len(a_array.dtype)))
>> array([[ 0., 1., 2., 3., 4.],
>> [ 1., 2., 3., 4., 5.]], dtype=float32)
>>
>> Ain't it fun ?
>
> Ah, yes, there is that niggle, too.
Except that I always get bitten by that:
>>> backandforth =
a_array.view(dtype=('f',len(a_array.dtype))).view(a_array.dtype)
>>> backandforth
array([[(0.0, 1.0, 2.0, 3.0, 4.0)],
[(1.0, 2.0, 3.0, 4.0, 5.0)]],
dtype=[('a', '<f4'), ('b', '<f4'), ('c', '<f4'), ('d', '<f4'),
('e', '<f4')])
>>> backandforth.shape
(2,1)
We gained a dimension !
More information about the NumPy-Discussion
mailing list