[Numpy-discussion] Converting char array to float

Pierre GM pgmdevlist at gmail.com
Wed Nov 28 13:51:58 EST 2007


On Wednesday 28 November 2007 13:39:45 Matthieu Brucher wrote:
> a does not seem to be an array, so it is not surprising that you need to
> convert it to an array first.

Well, a *IS* a regular chararray, and therefore a subclass of ndarray (try 
isinstance). The problem isn't here, it's that the subclass doesn't have its 
own .astype() method. Instead, we use the standard ndarray.astype, which 
calls the __array_finalize__ method from the subclass, and this one requires 
a chararray. Maybe we could implement a simple method:
def astype(self, newdtype):
    self.view(N.ndarray).astype(newdtype)
But wouldn't that break something down the line ?



More information about the NumPy-Discussion mailing list