Skip to content

coercion rules for boolean arrays are broken (Trac #453) #1051

Closed

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/453 on 2007-02-16 by @chanley, assigned to unknown.

In Python boolean multiplication results in the following:

In [1]: True * 4096
Out[1]: 4096

NUMARRAY is consistent with what you get from Python:

In [2]: import numarray

In [3]: a = numarray.ones(10,type=numarray.Bool)

In [4]: print a
[1 1 1 1 1 1 1 1 1 1]

In [5]: a * 4096
Out[5]: array([4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096])

However, numpy gives the following results:

In [6]: import numpy

In [7]: b = numpy.ones(10,dtype=numpy.bool_)

In [8]: print b
[ True  True  True  True  True  True  True  True  True  True]

In [9]: b * 4096
Out[9]: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int8)

The NUMPY coercion rules are not even self consistent. If you extract an element from array b to get a rank zero array you get the same behavior as Python:

In [10]: print b[0]
True

In [11]: b[0] * 4096
Out[11]: 4096

Activity

  1. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @teoliphant wrote on 2007-03-26

    This should be fixed in SVN, r3601

    The scalar/array coercion rule is that the type of the scalar will be ignored if the scalar is of the same kind or a lesser kind than the array.

    The recognized kinds are (in order)

    BOOL
    POSINT
    NEGINT
    FLOAT
    COMPLEX
    OBJECT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions