[Numpy-discussion] fixed_pt some progress and a question

josef.pktd@gmai... josef.pktd@gmai...
Tue Sep 29 09:51:00 CDT 2009


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?

Josef

>>> np.array(np.ldexp(obj, -obj.frac_bits))
array([ 0.,  1.,  2.,  3.,  4.])
>>> np.array(np.ldexp(obj, -obj.frac_bits)).dtype
dtype('float64')
>>> type(np.array(np.ldexp(obj, -obj.frac_bits)))
<type 'numpy.ndarray'>


More information about the NumPy-Discussion mailing list