[Numpy-discussion] Record arrays, nesting, and assignment
Vebjorn Ljosa
vebjorn@ljosa....
Wed Jul 15 14:19:29 CDT 2009
Suppose I have a record array where one of the fields is a nested array:
>>> from numpy import *
>>> desc = dtype([('point', 'i4', 3), ('unimportant', 'S3')])
>>> a = array([((1,2,3), 'foo'), ((7,8,9), 'bar')], dtype=desc)
>>> a
array([([1, 2, 3], 'foo'), ([7, 8, 9], 'bar')],
dtype=[('point', '<i4', 3), ('unimportant', '|S3')])
>>> a[0]
([1, 2, 3], 'foo')
If I try to assign to a[0]['point'], it only works partially:
>>> a[0]['point'] = array([4, 5, 6])
>>> a[0]
([4, 2, 3], 'foo')
However, if I assign to a['point'][0], it works:
>>> a['point'][0] = array([10, 11, 12])
>>> a[0]
([10, 11, 12], 'foo')
I should obviously remember to do it the second way ... but why does
the first way not work?
Thanks,
Vebjorn
P.S. In case it matters, numpy.__version__ == '1.2.1'.
More information about the NumPy-Discussion
mailing list