[Numpy-discussion] adding booleans
Sat Jun 8 08:06:09 CDT 2013
On Sat, Jun 8, 2013 at 7:54 AM, Robert Kern <email@example.com> wrote:
> On Sat, Jun 8, 2013 at 12:40 PM, <firstname.lastname@example.org> wrote:
>> Question about namespace
>> why is there bool and bool_ ?
>>>>> np.bool(True) + np.bool(True)
>>>>> np.bool_(True) + np.bool_(True)
>> <type 'bool'>
>> <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)
>>> 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.
> Robert Kern
> NumPy-Discussion mailing list
More information about the NumPy-Discussion