Indexing is the reading and changing of specific value in array
Read and change a value in array
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# import numpy library as np import numpy as np # Create an array one_dim = np.linspace(0.5, 0.6, 10) print(one_dim) # Get the value at third position print(one_dim[3]) # Change the value at third position one_dim[3] = 7 print(one_dim[3]) |
The above code will output this result
[0.5 0.51111111 0.52222222 0.53333333 0.54444444 0.55555556
0.56666667 0.57777778 0.58888889 0.6 ]
0.5333333333333333
7.0
Read and change a value in two dimensional array
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# import numpy library as np import numpy as np # Create an array two_dim = np.array([[1,2,3], [4,5,6], [7,8,9]]) print(two_dim) # Get the value at 0 row and 2 column position print(two_dim[0,2]) # Change the value at 0 row and 2 column position two_dim[0,2] = 44 print(two_dim[0,2]) |
The above code will output this result
[[1 2 3]
[4 5 6]
[7 8 9]]
3
44