[Numpy-discussion] Fwd: np.loadtxt : yet a new implementation...

John Hunter jdh2358@gmail....
Mon Dec 1 13:26:40 CST 2008


On Mon, Dec 1, 2008 at 1:14 PM, Pierre GM <pgmdevlist@gmail.com> wrote:

>> The problem you have is that the default dtype is 'float' (for
>> backwards compatibility w/ the original np.loadtxt). What you want
>> is to automatically change the dtype according to the content of
>> your file: you should use dtype=None
>>
>> r = loadtxt(sys.argv[1], delimiter=',', names=True, dtype=None)
>>
>> As you'll want a recarray, we could make a np.records.loadtxt
>> function where dtype=None would be the default...

> As you'll want a recarray, we could make a np.records.loadtxt function where
> dtype=None would be the default...

OK, that worked great.  I do think some a default impl in np.rec which
returned a recarray would be nice.  It might also be nice to have a
method like np.rec.fromcsv which defaults to a delimiter=',',
names=True and dtype=None.  Since csv is one of the most common data
interchange format in  the world, it would be nice to have some
obvious function that works with it with little or no customization
required.

Fernando and I have taught a scientific computing  course on a number
of occasions, and on the last round we taught to undergrads.  Most of
these students have little or no programming, for many the concept of
an array is something they struggle with, dtypes are a difficult
concept, but we found that they responded very well to our csv2rec
example, because with no syntactic cruft they were able to load a file
and do some stats on the columns, and I would like to see that ease of
use preserved.

JDH


More information about the Numpy-discussion mailing list