Hello,
I am writing due to an issue in structured array assignments. Let's
consider the following example:
In [31]: x = np.empty(1, dtype=[('field', 'i4', 10)])
In [32]: type(x[0])
Out[32]: numpy.void
In [33]: x[0] = np.ones(10, dtype='i4').view('V40')
In [34]: x
Out[34]:
array([([1, 1, 1, 1, 1, 1, 1, 1, 1, 1],)],
dtype=[('field', '<i4', (10,))])
In [42]: type(x[0]['field'])
Out[42]: numpy.ndarray
In [43]: x[0]['field'] = np.zeros(10, dtype='i4')
In [44]: x
Out[44]:
array([([0, 1, 1, 1, 1, 1, 1, 1, 1, 1],)],
dtype=[('field', '<i4', (10,))])
The assignments in both (33 and 43) call the C function
voidtype_ass_subscript, but the second call produces an unexpected
result --- it only copies the first element. 43 will work, if a slice
assignment (C function array_assign_slice) is forced by a left hand
[:] (that is x[0]['field'][:]).
The question now is: What is the general opinion about forcing slice
assignments for ndarray types and raising otherwise?
References:
* https://github.com/numpy/numpy/issues/3126
* https://github.com/numpy/numpy/pull/4556
Cheers,
mbyt
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion