Skip to content

Commit

Permalink
DOC: merge wiki changes, structured array doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgommers committed Mar 2, 2011
1 parent cbf7407 commit 7ef5d60
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion numpy/doc/structured_arrays.py
@@ -1,6 +1,6 @@
"""
=====================================
Structured Arrays (aka Record Arrays)
Structured Arrays (and Record Arrays)
=====================================
Introduction
Expand Down Expand Up @@ -173,4 +173,35 @@
>>> x.dtype.fields['x'][2]
'title 1'
Accessing multiple fields at once
====================================
You can access multiple fields at once using a list of field names: ::
>>> x = np.array([(1.5,2.5,(1.0,2.0)),(3.,4.,(4.,5.)),(1.,3.,(2.,6.))],
dtype=[('x','f4'),('y',np.float32),('value','f4',(2,2))])
Notice that `x` is created with a list of tuples.
>>> x[['x','y']]
array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)],
dtype=[('x', '<f4'), ('y', '<f4')])
>>> x[['x','value']]
array([(1.5, [[1.0, 2.0], [1.0, 2.0]]), (3.0, [[4.0, 5.0], [4.0, 5.0]]),
(1.0, [[2.0, 6.0], [2.0, 6.0]])],
dtype=[('x', '<f4'), ('value', '<f4', (2, 2))])
Notice that the fields are always returned in the same order regardless of
the sequence they are asked for.
>>> x[['y','x']]
array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)],
dtype=[('x', '<f4'), ('y', '<f4')])
More information
====================================
You can find some more information on recarrays and structured arrays
(including the difference between the two) `here
<http://www.scipy.org/Cookbook/Recarray>`_.
"""

0 comments on commit 7ef5d60

Please sign in to comment.