+ 1
Slicing a NumPy matrix in Python
import numpy as np A = np.array([[1, 4, 5, 12, 14], [-5, 8, 9, 0, 17], [-6, 7, 11, 19, 21]]) print(A[1,]) print(A[,1]) OUTPUT: [-5 8 9 0 17] error Why the second statement is wrong ?
1 ответ
+ 2
Because there is a comma after nothing thus program assumes it is safest to raise an error.
You can fix it by replacing the "nothing" with ":":
print(A[:, 1])
Anyways that was not slicing.