[Numpy-discussion] fixed_pt some progress and a question
Tue Sep 29 10:10:09 CDT 2009
> On Tue, Sep 29, 2009 at 10:22 AM, Neal Becker <email@example.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 : obj.as_double()
>> Out: 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
> 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).
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