[Numpy-discussion] loadtxt and usecols
Irvin Probst
irvin.probst at ensta-bretagne.fr
Tue Nov 10 11:39:05 EST 2015
On 10/11/2015 16:52, Daπid wrote:
> ((((42,)))) is exactly the same as (42,) If you want a tuple of
> tuples, you have to do ((42,),), but then it raises: TypeError: list
> indices must be integers, not tuple.
My bad, I wrote that too fast, please forget this.
> I think loadtxt should be a tool to read text files in the least
> surprising fashion, and a text file is a 1 or 2D container, so it
> shouldn't return any other shapes.
And I *do* agree with the "shouldn't return any other shapes" part of
your phrase. What I was trying to say, admitedly with a very bogus
example, is that either loadtxt() should always output an array whose
shape matches the shape of the object passed to usecol or it should
never do it, and I'm if favor of never.
I'm perfectly aware that what I suggest would break the current behavior
of usecols=(2,) so I know it does not have the slightest probability of
being accepted but still, I think that the "least surprising fashion" is
to always return an 2-D array because for many, many, many people a text
data file has N lines and M columns and N=1 or M=1 is not a specific case.
Anyway I will of course modify my PR according to any decision made here.
In your example:
>
> a=[[[2,],[],[],],[],[],[]]
> foo=np.loadtxt("CONCARNEAU_2010.txt", usecols=a)
>
> What would the shape of foo be?
As I said in my previous email:
> should just work and return me a 2-D (or 1-D if you like) array with
the data I asked for
So, 1-D or 2-D it is up to you, but as long as there is no ambiguity in
which columns the user is asking for it should imho work.
Regards.
More information about the NumPy-Discussion
mailing list