+ 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 ?

6th Jun 2019, 8:03 PM
harshit
harshit - avatar
1 Answer
+ 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.
6th Jun 2019, 8:07 PM
Seb TheS
Seb TheS - avatar