From 3d612274c0e6e8ed0dbbb98ca78fffdf67606b02 Mon Sep 17 00:00:00 2001 From: Derek Homier Date: Sat, 2 Apr 2011 20:16:32 -0600 Subject: ENH: ticket #1458, make loadtxt(..., unpack=True) unpack structured array fields. --- numpy/lib/npyio.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'numpy/lib/npyio.py') 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 -- cgit v1.2.1