[Numpy-discussion] array_equal returns True and 0

Keith Goodman kwgoodman@gmail....
Mon Jul 7 11:47:58 CDT 2008


On Mon, Jul 7, 2008 at 9:40 AM, Keith Goodman <kwgoodman@gmail.com> wrote:
> On Mon, Jul 7, 2008 at 9:30 AM, Keith Goodman <kwgoodman@gmail.com> wrote:
>> I'm writing the doc string for array_equal. From the existing one-line
>> doc string I expect array_equal to return True or False. But I get
>> this:
>>
>>>> np.array_equal([1,2], [1,2])
>>   True
>>>> np.array_equal([1,2], [1,2,3])
>>   0
>>>> np.array_equal(np.array([1,2]), np.array([1,2,3]))
>>   0
>>>> np.__version__
>>   '1.1.0'
>
> Oh, it's written in python:
>
> def array_equal(a1, a2):
>    """Returns True if a1 and a2 have identical shapes
>    and all elements equal and False otherwise.
>    """
>    try:
>        a1, a2 = asarray(a1), asarray(a2)
>    except:
>        return 0
>    if a1.shape != a2.shape:
>        return 0
>    return logical_and.reduce(equal(a1,a2).ravel())
>
> Could someone change the 0's to False? Otherwise it will return True,
> False or 0.
>
>>> np.array_equal([3,2], [1,2])
>   False

Sorry for all the messages.

array_equiv also returns 0.


More information about the Numpy-discussion mailing list