[Numpy-discussion] slices of structured arrays?

Ernest Adrogué eadrogue@gmx....
Tue Dec 8 19:32:25 CST 2009


Here's a structured array with fields 'a','b' and 'c':

s=[(i,int) for i in 'abc']

It has the form: array([(0, 0, 0)]

I was wondering if such an array can be accessed like an
ordinary array (e.g., with a slice) in order to set multiple
values at once.

t[0] does not access the first element of the array, instead
it returns the whole array.

In [329]: t[0]
Out[329]: (1, 0, 0)

But this array is type np.void and does not support slices.
t[0][0] returns the first element, but t[0][:2] fails with
IndexError: invalid index.

Any suggestion?


More information about the NumPy-Discussion mailing list