2

Say I have the following array:

a = array([(1L, 2.0, 'buckle_my_shoe'), (3L, 4.0, 'margery_door')], 
dtype=[('f0', '<i8'), ('f1', '<f8'), ('f2', 'S14')])

How do I access a column?

I can access a row using this syntax:

a[0][:]

but get an error when I try to access a column in the same way.

a[:][0]

Note. This is not a dupe of "How to access the ith column of a NumPy multidimensional array?" since I am using an array of different types.

1 Answer 1

2
In [33]: a['f0']
Out[33]: array([1, 3], dtype=int64)

In [34]: a['f1']
Out[34]: array([ 2.,  4.])

In [35]: a['f2']
Out[35]: 
array(['buckle_my_shoe', 'margery_door'], 
      dtype='|S14')

Here, f0, f1 and f2 are the field names from your array's dtype.

For more information, see Structured Arrays.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.