summaryrefslogtreecommitdiff
path: root/numpy/doc/structured_arrays.py
diff options
context:
space:
mode:
authorrgommers <ralf.gommers@googlemail.com>2011-03-02 12:21:01 +0800
committerrgommers <ralf.gommers@googlemail.com>2011-03-02 13:23:48 +0800
commit7ef5d601b4fe281c797fa497c317861c7340e3ec (patch)
tree7683db2c21e42372735432d51ed824f9961c95f3 /numpy/doc/structured_arrays.py
parentcbf74076e8bf13d8d2bf4abebb0f8ca576da8551 (diff)
downloadnumpy-7ef5d601b4fe281c797fa497c317861c7340e3ec.tar.gz
DOC: merge wiki changes, structured array doc.
Diffstat (limited to 'numpy/doc/structured_arrays.py')
-rw-r--r--numpy/doc/structured_arrays.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/numpy/doc/structured_arrays.py b/numpy/doc/structured_arrays.py
index 6eafd71cd..a0d84bd79 100644
--- a/numpy/doc/structured_arrays.py
+++ b/numpy/doc/structured_arrays.py
@@ -1,6 +1,6 @@
"""
=====================================
-Structured Arrays (aka Record Arrays)
+Structured Arrays (and Record Arrays)
=====================================
Introduction
@@ -173,4 +173,35 @@ They do not have to be strings.
>>> 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>`_.
+
"""