[Numpy-discussion] Re ading scientific notation using D instead of E
Christopher Barker
Chris.Barker@noaa....
Fri Feb 12 15:51:57 CST 2010
Robert Kern wrote:
> Eh, what? numpy.float is Python's float. No numpy features at all.
my mistake -- I guess I assumed that numpy.float was an alias for
numpy.float64.
anyway, the (all?) the numpy dtypes have their own implementation of
conversion from strings (which are a bit buggy, unfortunately).
They don't seem to be accessible in the same way, though:
In [44]: np.float64('1.23F+04')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Users/cbarker/HAZMAT/SmallTools/WxTool/trunk/tests/<ipython console> in
<module>()
ValueError: setting an array element with a sequence.
is the only way to do this:
In [49]: np.fromstring('1.23', dtype=np.float64, sep=' ')
Out[49]: array([ 1.23])
which is indeed, buggy (I wasn't aware of this bug yet):
In [51]: np.fromstring('1.23F+04', dtype=np.float64, sep=',')
Out[51]: array([ 1.23])
This make me think that the string conversion code is only being used by
fromstring/fromfile, and that it isn't used much there!
Which makes me wonder -- should we fix it or deprecate it?
If fix_it:
I wonder about the choice of strtod() and friends for the string
conversion -- is seems that fscans would be easier and more robust (or
easier to make robust, anyway)
-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