If you're willing to do arithmetic you might even be able to
pull it off, since NaNs tend to propagate:
if (newmin) min -= (min-new);
Whether the speed of this is worth its impenetrability I couldn't say.
Code comments cure impenetrability, and have no cost in speed. One
could write a
Availability of the NaN functionality in a method of ndarray
The last point is key. The NaN behavior is central to analyzing real
data containing unavoidable bad values, which is the bread and butter
of a substantial fraction of the user base. In the languages they're
switching from,
I'm doing nothing. Someone else must volunteer.
Fair enough. Would the code be accepted if contributed?
There is a
reasonable design rule that if you have a boolean argument which you
expect to only be passed literal Trues and Falses, you should instead
just have two different functions.
Travis E. Oliphant wrote:
Thomas J. Duck wrote:
Determining the minimum value of an array that contains NaN produces
a surprising result:
x = numpy.array([0,1,2,numpy.nan,4,5,6])
x.min()
4.0
I expected 0.0. Is this the intended behaviour or a bug? I am using
numpy 1.1.1.
2008/8/14 Norbert Nemec [EMAIL PROTECTED]:
Travis E. Oliphant wrote:
NAN's don't play well with comparisons because comparison with them is
undefined.See numpy.nanmin
This is not true! Each single comparison with a NaN has a well defined
outcome. The difficulty is only that certain
On 2008-08-14, Joe Harrington [EMAIL PROTECTED] wrote:
I'm doing nothing. Someone else must volunteer.
Fair enough. Would the code be accepted if contributed?
Like I said, I would be amenable to such a change. The other
developers haven't weighed in on this particular proposal, but I
suspect
Anne Archibald:
Sadly, it's not possible without extra overhead. Specifically: the
NaN-ignorant implementation does a single comparison between each
array element and a placeholder, and decides based on the result
which
to keep.
Did my example code go through? The test for NaN only
Robert Kern wrote:
Or we could implement the inner loop of the minimum ufunc to return
NaN if there is a NaN. Currently it just compares the two values
(which causes the unpredictable results since having a NaN on either
side of the is always False). I would be amenable to that provided
that
On Tue, Aug 12, 2008 at 19:28, Charles R Harris
[EMAIL PROTECTED] wrote:
On Tue, Aug 12, 2008 at 5:13 PM, Andrew Dalke [EMAIL PROTECTED]
wrote:
On Aug 12, 2008, at 9:54 AM, Anne Archibald wrote:
Er, is this actually a bug? I would instead consider the fact that
np.min([]) raises an
On Wed, Aug 13, 2008 at 14:37, Joe Harrington [EMAIL PROTECTED] wrote:
On Tue, Aug 12, 2008 at 19:28, Charles R Harris
[EMAIL PROTECTED] wrote:
On Tue, Aug 12, 2008 at 5:13 PM, Andrew Dalke [EMAIL PROTECTED]
wrote:
On Aug 12, 2008, at 9:54 AM, Anne Archibald wrote:
Er, is this actually a
Robert Kern wrote:
Or we could implement the inner loop of the minimum ufunc to return
NaN if there is a NaN. Currently it just compares the two values
(which causes the unpredictable results since having a NaN on either
side of the is always False). I would be amenable to that provided
that
On Wed, Aug 13, 2008 at 4:01 PM, Robert Kern [EMAIL PROTECTED] wrote:
On Wed, Aug 13, 2008 at 14:37, Joe Harrington [EMAIL PROTECTED] wrote:
On Tue, Aug 12, 2008 at 19:28, Charles R Harris
[EMAIL PROTECTED] wrote:
On Tue, Aug 12, 2008 at 5:13 PM, Andrew Dalke
[EMAIL PROTECTED]
wrote:
On Aug 12, 2008, at 7:05 AM, Christopher Barker wrote:
Actually, I think it skips over NaN -- otherwise, the min would always
be zero if there where a Nan, and a very small negative number if
there were a -inf.
Here's the implementation, from lib/function_base.py
def nanmin(a, axis=None):
Hi Andrew
2008/8/12 Andrew Dalke [EMAIL PROTECTED]:
This is buggy for the case of a list containing only NaNs.
import numpy as np
np.NAN
nan
np.min([np.NAN])
nan
np.nanmin([np.NAN])
inf
Thanks for the report. This should be fixed in r5630.
Regards
Stéfan
Masked arrays are a bit clunky for something as simple and standard as
NaN handling. They also have the inverse of the standard truth sense,
at least as used in my field. 1 (or True) usually means the item is
allowed, not denied, so that you can multiply the mask by the data to
zero all bad
2008/8/12 Stéfan van der Walt [EMAIL PROTECTED]:
Hi Andrew
2008/8/12 Andrew Dalke [EMAIL PROTECTED]:
This is buggy for the case of a list containing only NaNs.
import numpy as np
np.NAN
nan
np.min([np.NAN])
nan
np.nanmin([np.NAN])
inf
Thanks for the report. This should be
2008/8/12 Joe Harrington [EMAIL PROTECTED]:
So, I endorse extending min() and all other statistical routines to
handle NaNs, possibly with a switch to turn it on if a suitably fast
algorithm cannot be found (which is competitor IDL's solution).
Certainly without a switch the default behavior
On Tue, Aug 12, 2008 at 1:46 AM, Andrew Dalke [EMAIL PROTECTED]wrote:
Here's the implementation, from lib/function_base.py
def nanmin(a, axis=None):
Find the minimium over the given axis, ignoring NaNs.
y = array(a,subok=True)
if not issubclass(y.dtype.type, _nx.integer):
Anne Archibald wrote:
2008/8/12 Joe Harrington [EMAIL PROTECTED]:
So, I endorse extending min() and all other statistical routines to
handle NaNs, possibly with a switch to turn it on if a suitably fast
algorithm cannot be found (which is competitor IDL's solution).
Certainly without a
Thomas J. Duck wrote:
Determining the minimum value of an array that contains NaN produces
a surprising result:
x = numpy.array([0,1,2,numpy.nan,4,5,6])
x.min()
4.0
I expected 0.0. Is this the intended behaviour or a bug? I am using
numpy 1.1.1.
NAN's don't play well with
2008/8/11 Charles Doutriaux [EMAIL PROTECTED]:
Seems to me like min should automagically call nanmin if it spots any
nan no ?
Nanmin is quite a bit slower:
In [2]: x = np.random.random((5000))
In [3]: timeit np.min(x)
1 loops, best of 3: 24.8 µs per loop
In [4]: timeit np.nanmin(x)
21 matches
Mail list logo