I have an nd-array with names fields as below. I'm trying to assign values to multiple fields at once, but it seems to have no effect at all. See the example below:
In [380]: A = numpy.zeros(dtype=[("A", "f8"), ("B", "f8"), ("C", "f8")], shape=(5,))
In [381]: A[["A", "B", "C"]][0] = (2, 3, 4)
I would expect that now, these values are assigned to A, but in fact, the array is still all-zero:
In [382]: A[0]
Out[382]: (0.0, 0.0, 0.0)
When I index the other way around, I get an IndexError; (A[0]["A"] works, but A[0][["A", "B", "C"]] is IndexError:
In [383]: A[0][["A", "B", "C"]] = (2, 3, 4)
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-383-9b5cca19867a> in <module>()
----> 1 A[0][["A", "B", "C"]] = (2, 3, 4)
IndexError: invalid index
Why does A[fieldnames][0] = values not assign anything? Why does A[0][fieldnames] fail with an IndexError? How can I write multiple values at once to a structured array (apart from looping explicitly)?
A[0] = 2, 3, 4