I'm using:
- Python 3.5.4
- Numpy 1.16.2
Given the code:
import numpy as np
num = 3
a = np.asmatrix(np.eye(num, num))
b = np.asmatrix(range(0, num))
print(a[b].transpose())
I get the result:
[[1.00000000e+000 0.00000000e+000 0.00000000e+000]
[1.77658241e-307 0.00000000e+000 0.00000000e+000]
[3.47328271e-310 0.00000000e+000 0.00000000e+000]]
But by either changing the definition of b to np.asarray(...)
, or by performing a second indexing to get the first item in the list (print(a[b][0].transpose()
) I get the expected result:
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
What is going on? I've not experienced this bug before don't have a clue to the underlying cause. If its something fundamental to Python (I'm quite new to it still) I'd quite like to learn about it so that I don't sink quite as much time into debugging it as I have this time. Many thanks in advance.