In this section, we will see how to select the elements of the array. Let's see an example of a 2*2 matrix:
a = np.array([[5,6],[7,8]])
print(a)
Output:
[[5 6]
[7 8]]
In the preceding example, the matrix is created using the array() function with the input list of lists.
Selecting array elements is pretty simple. We just need to specify the index of the matrix as a[m,n]. Here, m is the row index and n is the column index of the matrix. We will now select each item of the matrix one by one as shown in the following code:
print(a[0,0])
Output: 5
print(a[0,1])
Output: 6
printa([1,0])
Output: 7
printa([1,1])
Output: 8
In the preceding code sample, we have tried to access each element of an array using array indices. You can also understand this by the diagram mentioned here:
In the preceding diagram, we can see it has four blocks and each block represents the element of an array. The values written in each block show its indices.
In this section, we have understood the...