[SciPy-User] scipy.stats.nanmedian

josef.pktd@gmai... josef.pktd@gmai...
Fri Jan 22 15:55:03 CST 2010


On Fri, Jan 22, 2010 at 4:52 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
> On Fri, Jan 22, 2010 at 1:44 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
>> On Fri, Jan 22, 2010 at 1:08 PM,  <josef.pktd@gmail.com> wrote:
>>> .item() returns a python number not a numpy number
>>>
>>>>>> np.array([[[1]]]).item().__class__
>>> <type 'int'>
>>>>>> np.array([[[1]]]).flat[0].__class__
>>> <type 'numpy.int32'>
>>
>> Good catch. Thanks. I'll update my local copy of nanmedian.
>
> Looks like we don't even need .tolist(), .item(), or [()]. This should
> do the trick:
>
>>> np.float64(np.array(1))
>   1.0
>>> type(np.float64(np.array(1)))
>   <type 'numpy.float64'>
>
> And what if the input is float32? Well, numpy turns that into float64
> so nothing to worry about:
>
>>> x = np.array(1, dtype=np.float32)
>>> m = np.median(x)
>>> type(m)
>   <type 'numpy.float64'>

but it breaks complex
>>> np.float64(np.array(1.j))
0.0

I did one more shape correction in my version

Josef

> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list