[Numpy-discussion] Converting char array to float

Matthieu Brucher matthieu.brucher@gmail....
Wed Nov 28 12:39:45 CST 2007


a does not seem to be an array, so it is not surprising that you need to
convert it to an array first.

Matthieu

2007/11/28, Sameer DCosta <sameerslists@gmail.com>:
>
> I'm trying to convert a character array to a floating point array. I'm
> using one of the recent svn builds. It is surprising that astype does
> not do the job. However if I first convert the char array to an array
> and then use astype everything works fine. Is this a bug?
>
> import numpy as N
> print N.__version__  # Output = '1.0.5.dev4426'
> a = N.char.array(['123.45', '234.56'])
> b = N.array(a).astype(N.float)  # This works.
> print b
> b = a.astype(N.float)   # This does not work and raises an exception
>
> ValueError: Can only create a chararray from string data.
>
>
> Thanks.
> Sameer
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
French PhD student
Website : http://miles.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20071128/675dd01f/attachment.html 


More information about the Numpy-discussion mailing list