![](https://secure.gravatar.com/avatar/a5c6e0b8f64a8a1940f5b2d367c1db6e.jpg?s=120&d=mm&r=g)
Integer exponentiation fails (i.e., changes type) with boolean dtype. See below. Expected? Alan Isaac >>> a = np.array([[0,1,0],[0,0,1],[1,0,0]], dtype=np.bool_) >>> a2 = a*a >>> a3 = a2*a >>> print(a3) [[False True False] [False False True] [ True False False]] >>> print(a**3) [[0 1 0] [0 0 1] [1 0 0]]
![](https://secure.gravatar.com/avatar/96dd777e397ab128fedab46af97a3a4a.jpg?s=120&d=mm&r=g)
On Wed, Oct 6, 2010 at 3:10 PM, Alan G Isaac <alan.isaac@gmail.com> wrote:
Integer exponentiation fails (i.e., changes type) with boolean dtype. See below. Expected?
Power isn't defined for booleans, I mean, who exponentiates booleans ;) What would you want in it's place? For consistancy, a**0 == all_true, a**i == a, i > 0? Chuck
![](https://secure.gravatar.com/avatar/96dd777e397ab128fedab46af97a3a4a.jpg?s=120&d=mm&r=g)
On Wed, Oct 6, 2010 at 4:12 PM, Alan G Isaac <alan.isaac@gmail.com> wrote:
On 10/6/2010 5:52 PM, Charles R Harris wrote:
What would you want in it's place? For consistancy, a**0 == all_true, a**i == a, i > 0?
Yes.
Alan Isaac
PS Boolean matrix powers are well defined and useful. I found this oddity by accidentally creating an array instead of a matrix.
Open an enhancement ticket then, with clear instructions as to what you want. What about fractional/negative exponents? I mean, the definition extends to positive rationals without problem given a discontinuity when the exponent goes to zero but negative exponents are a problem for False. Chuck
participants (2)
-
Alan G Isaac
-
Charles R Harris