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

Christopher Barker Chris.Barker@noaa....
Wed Dec 3 12:14:02 CST 2008


Pierre GM wrote:
> Oh, don;t worry, nothing too fancy: give me a couple lines of input  
> data and a line with what you expect.

I just went and looked at the existing tests, and you're right, it's 
very easy -- my first foray into the new nose tests -- very nice!

>> specify, say ',' as the delimiter, it won't use '\n', only  a comma,  
>> so
>> there is no way to quickly read a whole bunch of comma delimited  
>> data like:
>>
>> 1,2,3,4
>> 5,6,7,8
>> ....
>>
>> so I'd like to be able to say to use either ',' or '\n' as the  
>> delimiter.
> 
> I'm not quite sure I follow you.
> Do you want to delimiters, one for the field of a record (','), one  
> for the records ("\n") ?

well, in the case of fromfile(), it doesn't "do" records -- it will only 
give you a 1-d array, so I want it all as a flat array, and you can 
re-size it yourself later. Clearly this is more work (and requires more 
knowledge of your data) than using loadtxt, but sometimes I really want 
FAST data reading of simple formats.

However, this isn't fromfile() we are talking about now, it's loadtxt()...

>> So how likely is it that someone would have:
>>
>> 1  2  3, 4, 5
>> 6  7  8, 8, 9
>>
>> and want to read that into a single 2-d array?
> 
> With the current behaviour, you gonna have
> [("1 2 3", 4, 5), ("6 7 8", 8, 9)] if you use "," as a delimiter,
> [(1,2,"3,","4,",5),(6,7,"8,","8,",9)] if you use " " as a delimiter.

right.

> Mixing delimiter is doable, but I don't think it's that a good idea.  

I can't come up with a use case at this point, so..

> I'm in favor of sticking to one and only field delimiter, and the  
> default line spearator for record delimiter. In other terms, not  
> changing anything.

I agree -- sorry for the noise!

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the Numpy-discussion mailing list