[Numpy-discussion] fast robus implementation of float()

Christopher Barker Chris.Barker at noaa.gov
Tue Mar 22 22:38:04 EDT 2011


On 3/22/11 1:54 PM, Christian K. wrote:
> I wonder if someone has a good solution for a fast conversion of gridded
> ascii data to ndarray.

the fastest out of the box way is with np.fromfile(input_file, sep=" ", 
dtype=np.float)

It will only read multiple lines if the separater is whitespace, but 
it's pretty fast if it does.

> It should manage ',' as decimal point (on demand)

I think that will work ig the locale is set right, though I don't know 
how to do that "on demand"

> and special windows numbers as 1.#INF.

I can't remember if it does that -- give it a try. It does use 
ascii-to-float function written for numpy to handle things like that.

> Of course, this is easy to wrap
> in a small function but I expect it to be slow when the input size is in
> the Mb range.

Never expect -- do a simple solution, then see if it's too slow for 
youre needs.

-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 at noaa.gov



More information about the NumPy-Discussion mailing list