[SciPy-User] scipy.stats.nanmedian
Bruce Southey
bsouthey at gmail.com
Fri Jan 22 10:58:07 EST 2010
On 01/21/2010 10:18 PM, josef.pktd at gmail.com wrote:
> On Thu, Jan 21, 2010 at 10:01 PM, Keith Goodman<kwgoodman at gmail.com> wrote:
>
>> On Thu, Jan 21, 2010 at 6:41 PM, Pierre GM<pgmdevlist at gmail.com> wrote:
>>
>>> On Jan 21, 2010, at 9:28 PM, Keith Goodman wrote:
>>>
>>>> That's the only was I was able to figure out how to pull 1.0 out of
>>>> np.array(1.0). Is there a better way?
>>>>
>>>
>>> .item()
>>>
>> Thanks. item() looks better than tolist().
>>
>> I simplified the function:
>>
>> def nanmedian(x, axis=0):
>> x, axis = _chk_asarray(x,axis)
>> if x.ndim == 0:
>> return float(x.item())
>> x = x.copy()
>> x = np.apply_along_axis(_nanmedian,axis,x)
>> if x.ndim == 0:
>> x = float(x.item())
>> return x
>>
>> and opened a ticket:
>>
>> http://projects.scipy.org/scipy/ticket/1098
>>
>
> How about getting rid of apply_along_axis? see attachment
>
> I don't know whether or how much faster it is, but there is a ticket
> that the current version is slow.
> No hidden bug or corner case guarantee yet.
>
>
> Josef
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
Personally, I think using masked arrays is a far better solution than
the various nan methods in stats.py. Is the call to _chk_asarray that
much different than the call to ma? Both require conversion or checking
if the input is a np array.
As stated in the documentation, _nanmedian only works on 1d arrays. So
any 'axis' argument without changing the main function is perhaps a hack
at best.
Is it possible to adapt Sturla's version?
http://projects.scipy.org/numpy/ticket/1213
I do not know the algorithm to suggest anything but perhaps the select
method could be adapted to handle nan.
Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100122/528325f6/attachment.html>
More information about the SciPy-User
mailing list