[Numpy-discussion] fixed_pt some progress and a question

Neal Becker ndbecker2@gmail....
Tue Sep 29 10:10:09 CDT 2009

josef.pktd@gmail.com wrote:

> On Tue, Sep 29, 2009 at 10:22 AM, Neal Becker <ndbecker2@gmail.com> wrote:
>> This doesn't work either:
>> def as_double (self):
>> import math
>> def _as_double_1 (x):
>> return math.ldexp (x, -self.frac_bits)
>> vecfunc = np.vectorize (_as_double_1, otypes=[np.float])
>> return vecfunc (self)
>> In [49]: obj.as_double()
>> Out[49]: fixed_pt_array([ 0.,  1.,  2.,  3.,  4.])
>> The values are correct, but I wanted a float array, not fixed_pt_array
>> for output.
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> I don't understand much, but if you just want to convert to a regular
> float array, you can just create a new array with np.array  in
> as_double, or not?

I could force an additional conversion using np.array (xxx, dtype=float).  
Seems wasteful.

The bigger question I have is, if I've subclassed an array, how can I get at 
the underlying array type?  In this example, fixed_pt is really an 'int64' 
array.  But I can't find any way to get that.  Any function such as 'view' 
just silently does nothing.  It always returns the fixed_pt_array class.

Consider the fixed_pt_array method as_base().  It should return the 
underlying int array.  How could I do this? 

More information about the NumPy-Discussion mailing list