Perform the following Indexing Operations using Numpy array. array2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) . Data science using Python in Anaconda - Jupyter
Question
1. Get first row first col
2. Get first row second col
3. Get first row second col
4. Get second row second col
Program: -
import numpy as np
array2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
array2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(array2d)
print("first row first col :- ",array2d[0:1, 0:1])
print("first row second col :- ",array2d[0:1,1:2])
print("second row first col :- ",array2d[1:2,0:1])
print("second row second col :- ",array2d[1:2,1:2])
Output: -
[[1 2 3]
[4 5 6]
[7 8 9]]
first row first col :- [[1]]
first row second col :- [[2]]
second row first col :- [[4]]
second row second col :- [[5]]