[Numpy-discussion] Preventing an ndarray subclass from returning new subclass instances for std(), etc

josef.pktd@gmai... josef.pktd@gmai...
Sun Sep 18 12:08:09 CDT 2011


On Sun, Sep 18, 2011 at 12:48 PM, Keith Hughitt <keith.hughitt@gmail.com> wrote:
> Interesting. It works as expected when called as a method:
>
> In [10]: x = np.ma.array([[1,2,3]])
> In [11]: x.std()
> Out[11]: 0.81649658092772603

That's only the treatment of scalars in std

>>> x = np.ma.array(np.random.randn(4,5))
>>> x.std(0)
masked_array(data = [0.842985810318 0.423312129749 0.607139983509
0.583121781933 0.681360542632],
             mask = [False False False False False],
       fill_value = 1e+20)

Josef

>
> but not for my class:
>
> In [14]: aia.std()
> Out[14]: AIAMap(292.4342470467856)
> In [15]: np.std(aia)
> Out[15]: AIAMap(292.4342470467856)
> In [16]: np.array(aia).std()
> Out[16]: 292.43424704678557
>
> Keith
> 2011/9/18 Stéfan van der Walt <stefan@sun.ac.za>
>>
>> On Sun, Sep 18, 2011 at 9:09 AM, Keith Hughitt <keith.hughitt@gmail.com>
>> wrote:
>> > I'm sure it is simply a coding error on my part, but so far I havne't
>> > been
>> > able to track it down.
>>
>> I don't think it's something you've done wrong.  See e.g.:
>>
>> In [9]: x = np.ma.array([[1,2,3]])
>>
>> In [10]: np.std(x, axis=0)
>> Out[10]:
>> masked_array(data = [0.0 0.0 0.0],
>>             mask = [False False False],
>>       fill_value = 1e+20)
>>
>> Regards
>> Stéfan
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>


More information about the NumPy-Discussion mailing list