summaryrefslogtreecommitdiff
path: root/numpy/core/_internal.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2009-02-12 04:22:03 +0000
committerTravis Oliphant <oliphant@enthought.com>2009-02-12 04:22:03 +0000
commit0672fd89b34b298928ca186af8ebee41d927da8f (patch)
tree9b8b45d4aa32b82d9c9f6366d3c47035122906e1 /numpy/core/_internal.py
parent27562549af2d04f89328fcceb99ad8aa956bc978 (diff)
downloadnumpy-0672fd89b34b298928ca186af8ebee41d927da8f.tar.gz
Add multiple-field access by making a copy of the array and filling with the selected fields.
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r--numpy/core/_internal.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index 558d2fe93..7d5c3a49e 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -292,3 +292,22 @@ def _newnames(datatype, order):
raise ValueError, "unknown field name: %s" % (name,)
return tuple(list(order) + nameslist)
raise ValueError, "unsupported order value: %s" % (order,)
+
+# Given an array with fields and a sequence of field names
+# construct a new array with just those fields copied over
+def _index_fields(ary, fields):
+ from multiarray import empty, dtype
+ dt = ary.dtype
+ new_dtype = [(name, dt[name]) for name in dt.names if name in fields]
+ if ary.flags.f_contiguous:
+ order = 'F'
+ else:
+ order = 'C'
+
+ newarray = empty(ary.shape, dtype=new_dtype, order=order)
+
+ for name in fields:
+ newarray[name] = ary[name]
+
+ return newarray
+