Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Allow genfromtxt to unpack structured arrays (#16650)
* ENH: Allow genfromtxt to unpack structured arrays genfromtxt failed to transpose output when unpack=True and `dtype` was structured (or None). This patch resolves the issue by returning a list of arrays, as in `loadtxt`. Co-authored-by: Matti Picus <matti.picus@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
- Loading branch information
1 parent
02798e4
commit 3329d26
Showing
3 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
`numpy.genfromtxt` now correctly unpacks structured arrays | ||
---------------------------------------------------------- | ||
Previously, `numpy.genfromtxt` failed to unpack if it was called with | ||
``unpack=True`` and a structured datatype was passed to the ``dtype`` argument | ||
(or ``dtype=None`` was passed and a structured datatype was inferred). | ||
For example:: | ||
|
||
>>> data = StringIO("21 58.0\n35 72.0") | ||
>>> np.genfromtxt(data, dtype=None, unpack=True) | ||
array([(21, 58.), (35, 72.)], dtype=[('f0', '<i8'), ('f1', '<f8')]) | ||
|
||
Structured arrays will now correctly unpack into a list of arrays, | ||
one for each column:: | ||
|
||
>>> np.genfromtxt(data, dtype=None, unpack=True) | ||
[array([21, 35]), array([58., 72.])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters