[SciPy-User] scipy.stats.nanmedian

Keith Goodman kwgoodman at gmail.com
Fri Jan 22 16:52:04 EST 2010


On Fri, Jan 22, 2010 at 1:44 PM, Keith Goodman <kwgoodman at gmail.com> wrote:
> On Fri, Jan 22, 2010 at 1:08 PM,  <josef.pktd at 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'>



More information about the SciPy-User mailing list