[Numpy-discussion] loadtxt and usecols
Sebastian Berg
sebastian at sipsolutions.net
Tue Nov 10 08:17:32 EST 2015
On Di, 2015-11-10 at 10:24 +0100, Irvin Probst wrote:
> On 10/11/2015 09:19, Sebastian Berg wrote:
> > since a scalar row (so just one row) is read and not a 2D array. I tend
> > to say it should be an array-like argument and not a generalized
> > sequence argument, just wanted to note that, since I am not sure what
> > matlab does.
>
> Hi,
> By default Matlab reads everything, silently fails on what can't be
> converted into a float and the user has to guess what was read or not.
> Say you have a file like this:
>
> 2010-01-01 00:00:00 3.026
> 2010-01-01 01:00:00 4.049
> 2010-01-01 02:00:00 4.865
>
>
> >> M=load('CONCARNEAU_2010.txt');
> >> M(1:3,:)
>
> ans =
>
> 1.0e+03 *
>
> 2.0100 0 0.0030
> 2.0100 0.0010 0.0040
> 2.0100 0.0020 0.0049
>
>
> I think this is a terrible way of doing it even if newcomers might find
> this handy. There are of course optionnal arguments (even regexps !) but
> to my knowledge almost no Matlab user even knows these arguments are there.
>
> Anyway, I made a PR here https://github.com/numpy/numpy/pull/6656 with
> usecols as an array-like.
>
Actually, it is the "sequence special case" type ;). (matlab does not
have this, since matlab always returns 2-D I realized).
As I said, if usecols is like indexing, the result should mimic:
arr = np.loadtxt(f)
arr = arr[usecols]
in which case a 1-D array is returned if you put in a scalar into
usecols (and you could even generalize usecols to higher dimensional
array-likes).
The way you implemented it -- which is fine, but I want to stress that
there is a real decision being made here --, you always see it as a
sequence but allow a scalar for convenience (i.e. always return a 2-D
array). It is a `sequence of ints or int` type argument and not an
array-like argument in my opinion.
- Sebastian
> Regards.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151110/b11438a3/attachment.sig>
More information about the NumPy-Discussion
mailing list