question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

genfromtxt won't unpack if dtype=None

See original GitHub issue

Not sure if this is a bug or a feature but if I use:

f_data = np.genfromtxt('file.dat', dtype=None, unpack=True)

where file.dat is a standard data file with several columns (ie: http://pastebin.com/ihEW2dxS) the result is not transposed as one would expect having set unpack=True.

For example, the line f_data = np.loadtxt('file.dat', unpack=True) works as expected.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
moi90commented, Dec 22, 2017

I also experience this. loadtxt is a bit more clever:

if unpack:
        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

Why doesn’t genfromtxt do this?

1reaction
WarrenWeckessercommented, Jun 10, 2020

The suggestion @moi90 made a couple years ago is correct. genfromtxt should do the same thing as loadtxt.

I think it will be easy to fix, so I’ve tagged the issue as a “good first issue”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy.genfromtxt is not unpacking - Stack Overflow
The issue is that when the data is loaded it is a shape of (N,). dtype=None is in place so that the data...
Read more >
numpy.genfromtxt — NumPy v1.23 Manual
If True, the returned array is transposed, so that arguments may be unpacked using x, y, z = genfromtxt(...) . When used with...
Read more >
Importing data with genfromtxt — NumPy v1.9 Manual
Once the file is defined and open for reading, genfromtxt splits each non-empty line into a sequence of strings. Empty or commented lines...
Read more >
numpy.genfromtxt — NumPy v1.9 Manual
For example, usecols = (1, 4, 5) will extract the 2nd, 5th and 6th columns. names : {None, True, str, sequence}, optional. If...
Read more >
NumPy Input and Output: genfromtxt() function - w3resource
unpack, If True, the returned array is transposed, ... needed for StringIO example only >>> data1 = np.genfromtxt(str, dtype=None, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found