[Numpy-discussion] Converting char array to float

Pierre GM pgmdevlist@gmail....
Wed Nov 28 12:37:20 CST 2007


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 
* You can also view your charray as a regular ndarray, and then use the astype 

More information about the Numpy-discussion mailing list