[Numpy-discussion] adding booleans

josef.pktd@gmai... josef.pktd@gmai...
Sat Jun 8 08:06:09 CDT 2013


On Sat, Jun 8, 2013 at 7:54 AM, Robert Kern <robert.kern@gmail.com> wrote:
> On Sat, Jun 8, 2013 at 12:40 PM,  <josef.pktd@gmail.com> wrote:
>> Question about namespace
>>
>> why is there bool and bool_ ?
>>
>>>>> np.bool(True) + np.bool(True)
>> 2
>>>>> np.bool_(True) + np.bool_(True)
>> True
>>
>>>>> type(np.bool(True))
>> <type 'bool'>
>>>>> type(np.bool_(True))
>> <type 'numpy.bool_'>
>>
>> I didn't pay attention to the trailing underline in Pauli's original example
>
> `np.bool is __builtin__.bool`. It's a backwards-compatibility alias
> for an old version of numpy that used the name `np.bool` for the
> scalar type now called `np.bool_` (similarly for `np.float`, `np.int`,
> and `np.complex`). Since `from numpy import *` caused name collisions,
> we moved the scalar types to their current underscored versions.
> However, since people had started to use `dtype=np.bool`, we just
> aliased the builtin type objects to keep that code working. I would
> love to be able to remove those since they are an unending source of
> confusion. However, there is no good way to issue deprecation warnings
> when you use them, so that means that upgrades would cause sudden,
> unwarned breakage, which we like to avoid.

Thanks for the explanation.

I guess I never ran into a problem with this, and never saw the difference.

It's confusing, but if the behavior is the same (in all usual cases)
whether it's python or numpy, then it is less of a problem.

>>> np.int64(0) ** np.int64(-1)
inf
>>> np.int(0) ** np.int(-1)
Traceback (most recent call last):
  File "<pyshell#169>", line 1, in <module>
    np.int(0) ** np.int(-1)
ZeroDivisionError: 0.0 cannot be raised to a negative power

Another thing to watch out for.

Josef

>
> --
> Robert Kern
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list