[SciPy-User] scipy.stats.nanmedian

josef.pktd@gmai... josef.pktd@gmai...
Fri Jan 22 10:14:56 CST 2010


On Fri, Jan 22, 2010 at 10:58 AM, Bruce Southey <bsouthey@gmail.com> wrote:
> On 01/21/2010 10:18 PM, josef.pktd@gmail.com wrote:
>
> On Thu, Jan 21, 2010 at 10:01 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
>
>
> On Thu, Jan 21, 2010 at 6:41 PM, Pierre GM <pgmdevlist@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@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.

I like arrays with nans better than masked arrays, and I checked,
np.ma.median also uses apply_along_axis and I wanted to see if I can
get a vectorized version.

>
> 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.

_nanmedian is an internal function, stats.nanmedian and my rewritten
version are supposed to handle any dimension and any axis.

>
> 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.

I guess Sturla's version is a lot better, but not my kind of fish,
it's more for the algorithm and c experts. I will gladly use it once
it or something similar is in numpy.

Josef

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


More information about the SciPy-User mailing list