[Numpy-discussion] .max(0) on reshaped array returns inconsistent results.

Thouis Jones thouis.jones at curie.fr
Fri May 25 08:07:46 EDT 2012

On Fri, May 25, 2012 at 1:52 PM, Nathaniel Smith <njs at pobox.com> wrote:
> On Fri, May 25, 2012 at 12:46 PM, Thouis (Ray) Jones <thouis at gmail.com> wrote:
>> I'm seeing some strange behavior from .max() on a reshaped array in
>> the current master, and wanted to raise it here to make sure it's not
>> something uniquely broken in my setup.
>> This code fails for me, though changing the context (adding a counter
>> to the loop, or running under "python -i") sometimes prevents it from
>> failing.  This code doesn't fail under 1.6.2.
>> ---------------
>> import numpy as np
>> b = np.array([0, 1, 2, 3, 4, 5], np.int64)
>> a = b.reshape(3, 2)
>> while True:
>>    np.testing.assert_array_equal(np.atleast_1d(np.array(a.max(0), np.float)),
>>                                  np.atleast_1d(np.array(a.max(0), np.float)))
>> ---------------
>> I spent several hours with valgrind trying to track down what was
>> causing this, but had no luck.  Perhaps someone with more knowledge of
>> the numpy ufunc internals can track it down faster than me.
> What do you get, if not the expected value? And are the calls to
> atleast_1d, np.array, etc., necessary to trigger the problem, or will
> just plain a.max(0) do it?

Arrays are not equal
(mismatch 100.0%)
 x: array([ 4.,  5.])
 y: array([  4.31441533e+09,   4.31441402e+09])

I don't seem to be able to reproduce with just a.max(0) or
np.array(a.max(0), np.float), but since it seems to be very unstable
to other changes in the code, I'll keep trying to find out if I can
make those simpler versions crash.

Ray Jones

More information about the NumPy-Discussion mailing list