[Numpy-discussion] Converting char array to float
Pierre GM
pgmdevlist at gmail.com
Wed Nov 28 13:37:20 EST 2007
Sameer,
I can't tell whether it's a bug or a feature, but I can give you some
explanation: when you call .astype on your chararray, you call the
__array_finalize__ of the chararray, which requires the dtype to be string
like. Obviously, that won't work in your case. Transforming the chararray to
a regular array of strings bypass this problem. That's what you're doing with
the N.array(a) statement in your example.
Two comments, however:
* Try to use N.asarray() instead, as you won't copy the data (or use
N.array(a,copy=False))
* You can also view your charray as a regular ndarray, and then use the astype
method:
a.view(N.ndarray).astype(float_)
More information about the NumPy-Discussion
mailing list