[Tutor] strange behavior of matrix**matrix
A.Brozi
brozi at toya.net.pl
Sun Jul 17 08:41:33 EDT 2016
Hello
I'm puzzling over some strange behavior of raising a matrix to a matrix
power:
If I create two matrices (containing integers):
a = np.array([2])
and
b = np.array([-1])
the operation a**b produces:
array([0], dtype=int32)
The result of division b/a is correct:
array([-0.5])
If any one of the matrices is float (i.e. created with the use of
dtype=float) the result is correct, i.e. a**b produces:
array([ 0.5])
If a and b are single integer 32 numbers, e.g. obtained with:
a = np.int32(2)
and
b = np.int32(-1)
the same operation a**b produces:
0.5
as expected.
Perhaps it's somehow related to the 'old' integer division of Pythons 2.x.
I wonder if it's a bug or a feature.
And if it's a feature, then what is it useful for?
I'm on Python 3.5.1 64bit via Spyder 3.0.0dev, numpy 1.9.3, scipy 0.16.1
(all installed from WinPython-64bit-3.5.1.3.exe), running on Windows 10.
Regards
Andrzej Brozi
More information about the Tutor
mailing list