diff options
author | Derek Homier <derek@astro.physik.uni-goettingen.de> | 2011-04-02 20:16:32 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-04-02 20:16:32 -0600 |
commit | 3d612274c0e6e8ed0dbbb98ca78fffdf67606b02 (patch) | |
tree | a5a72f44a02f3faa4734ce813254c67523bab5ca /numpy/lib/npyio.py | |
parent | 9b354f4dc00e3aef4cfceae71be60b1dc60a1927 (diff) | |
download | numpy-3d612274c0e6e8ed0dbbb98ca78fffdf67606b02.tar.gz |
ENH: ticket #1458, make loadtxt(..., unpack=True) unpack structured array
fields.
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 9e23ba3fe..263aa82c2 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -619,7 +619,8 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, The default, None, results in all columns being read. unpack : bool, optional If True, the returned array is transposed, so that arguments may be - unpacked using ``x, y, z = loadtxt(...)``. The default is False. + unpacked using ``x, y, z = loadtxt(...)``. When used with a record + data-type, arrays are returned for each field. Default is False. Returns ------- @@ -797,7 +798,11 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, X = np.squeeze(X) if unpack: - return X.T + if len(dtype_types) > 1: + # For structured arrays, return an array for each field. + return [X[field] for field in dtype.names] + else: + return X.T else: return X |