
I'm writing unit tests for a module that contains matrices. I was surprised that these are True:
import numpy.matlib as mp x = mp.matrix([[mp.nan]]) x.any() True x.all() True
My use case is (x == y).all() where x and y are the same matrix except that x contains one NaN. Certianly x and y are not equal.
x = mp.asmatrix(range(4)).reshape(2,2) y = mp.asmatrix(range(4)).reshape(2,2) x[0,0] = mp.nan (x == y).all() True

On Fri, May 23, 2008 at 10:16 AM, Keith Goodman <kwgoodman@gmail.com> wrote:
I'm writing unit tests for a module that contains matrices. I was surprised that these are True:
import numpy.matlib as mp x = mp.matrix([[mp.nan]]) x.any() True x.all() True
My use case is (x == y).all() where x and y are the same matrix except that x contains one NaN. Certianly x and y are not equal.
x = mp.asmatrix(range(4)).reshape(2,2) y = mp.asmatrix(range(4)).reshape(2,2) x[0,0] = mp.nan (x == y).all() True
Sorry. Ignore the last example. I used integers. Here's the example with floats:
x = 1.0 * mp.asmatrix(range(4)).reshape(2,2) y = 1.0 * mp.asmatrix(range(4)).reshape(2,2) x[0,0] = mp.nan x
matrix([[ NaN, 1.], [ 2., 3.]])
(x == y).all() False
But the first example
x = mp.matrix([[mp.nan]]) x matrix([[ NaN]]) x.all() True x.any() True
is still surprising.

On Fri, May 23, 2008 at 12:22 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
But the first example
x = mp.matrix([[mp.nan]]) x matrix([[ NaN]]) x.all() True x.any() True
is still surprising.
On non-boolean arrays, .all() and .any() check each element to see if it is not equal to 0. NaN != 0. Returning False would be just as wrong. If there were a Maybe in addition to True and False, then perhaps that would be worth changing, but I don't see a reason to change the rule as it is. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco

On Fri, May 23, 2008 at 11:44 AM, Robert Kern <robert.kern@gmail.com> wrote:
On Fri, May 23, 2008 at 12:22 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
But the first example
x = mp.matrix([[mp.nan]]) x matrix([[ NaN]]) x.all() True x.any() True
is still surprising.
On non-boolean arrays, .all() and .any() check each element to see if it is not equal to 0. NaN != 0. Returning False would be just as wrong. If there were a Maybe in addition to True and False, then perhaps that would be worth changing, but I don't see a reason to change the rule as it is.
That makes sense. Hopefully it will find its way into the doc string. If I want NaNs to be False I can always do (x == x).all() instead of x.all()

2008/5/23 Keith Goodman <kwgoodman@gmail.com>:
On Fri, May 23, 2008 at 11:44 AM, Robert Kern <robert.kern@gmail.com> wrote:
On Fri, May 23, 2008 at 12:22 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
But the first example
x = mp.matrix([[mp.nan]]) x matrix([[ NaN]]) x.all() True x.any() True
is still surprising.
On non-boolean arrays, .all() and .any() check each element to see if it is not equal to 0. NaN != 0. Returning False would be just as wrong. If there were a Maybe in addition to True and False, then perhaps that would be worth changing, but I don't see a reason to change the rule as it is.
That makes sense. Hopefully it will find its way into the doc string.
Hopefully you'll add it there :) Cheers Stéfan

On Thu, May 29, 2008 at 9:26 AM, Stéfan van der Walt <stefan@sun.ac.za> wrote:
2008/5/23 Keith Goodman <kwgoodman@gmail.com>:
On Fri, May 23, 2008 at 11:44 AM, Robert Kern <robert.kern@gmail.com> wrote:
On Fri, May 23, 2008 at 12:22 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
But the first example
x = mp.matrix([[mp.nan]]) x matrix([[ NaN]]) x.all() True x.any() True
is still surprising.
On non-boolean arrays, .all() and .any() check each element to see if it is not equal to 0. NaN != 0. Returning False would be just as wrong. If there were a Maybe in addition to True and False, then perhaps that would be worth changing, but I don't see a reason to change the rule as it is.
That makes sense. Hopefully it will find its way into the doc string.
Hopefully you'll add it there :)
Yeah, but then I'd have to change these it's to its: Docstrings/numpy/ma/extras/polyfit . . . 1 match ...me when y is a 2D array. When full=True, the rank of the scaled Vandermonde matrix, it's effective rank in light of the rcond value, its singular values, and the specified ... Docstrings/numpy/lib/polynomial/polyfit . . . 1 match ...me when y is a 2D array. When full=True, the rank of the scaled Vandermonde matrix, it's effective rank in light of the rcond value, its singular values, and the specified ... Docstrings/numpy/lib/index-tricks/nd-grid . . . 1 match ...However, if the step length is a **complex number** (e.g. 5j), then the integer part of it's magnitude is interpreted as specifying the number of points to create between the start... Docstrings/numpy/lib/-datasource/Repository . . . 1 match ...one base URL. Initialize the Respository with the base URL, then refer to each file by it's filename only. *Methods*: - exists : test if the file exists locally or remotely ... Docstrings/numpy/fft/fftpack/ifft . . . 1 match ...input array is expected to be packed the same way as the output of fft, as discussed in it's documentation. This is the inverse of fft: ifft(fft(a)) == a within numerical accuracy...

On Thu, May 29, 2008 at 9:26 AM, Stéfan van der Walt <stefan@sun.ac.za> wrote:
2008/5/23 Keith Goodman <kwgoodman@gmail.com>:
On Fri, May 23, 2008 at 11:44 AM, Robert Kern <robert.kern@gmail.com> wrote:
On Fri, May 23, 2008 at 12:22 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
But the first example
x = mp.matrix([[mp.nan]]) x matrix([[ NaN]]) x.all() True x.any() True
is still surprising.
On non-boolean arrays, .all() and .any() check each element to see if it is not equal to 0. NaN != 0. Returning False would be just as wrong. If there were a Maybe in addition to True and False, then perhaps that would be worth changing, but I don't see a reason to change the rule as it is.
That makes sense. Hopefully it will find its way into the doc string.
Hopefully you'll add it there :)
Cheers Stéfan
My username is kwgoodman.

to, 2008-05-29 kello 10:53 -0700, Keith Goodman kirjoitti:
On Thu, May 29, 2008 at 9:26 AM, Stéfan van der Walt <stefan@sun.ac.za> wrote:
2008/5/23 Keith Goodman <kwgoodman@gmail.com>:
On Fri, May 23, 2008 at 11:44 AM, Robert Kern <robert.kern@gmail.com> wrote: [clip] That makes sense. Hopefully it will find its way into the doc string.
Hopefully you'll add it there :)
Cheers Stéfan
My username is kwgoodman.
Thanks, edit permissions added. Pauli
participants (4)
-
Keith Goodman
-
Pauli Virtanen
-
Robert Kern
-
Stéfan van der Walt