2D NumPy arrays
An element of a two-dimensional array is accessed by specifying the coordinates of the element, first the row number, then the column number. Coordinates are separated by commas.
Any array can be converted to a two-dimensional array using the
reshape().
function
Example
1
2
3
4
5
6
7
8
|
# The reshape() function changes the shape of an array without changing its data.
x = np.arange(12).reshape(3, 4)
print(x) # [[ 0 1 2 3]
# [ 4 5 6 7]
# [ 8 9 10 11]]
# To access an element, specify its coordinates separated by commas
print(x[1, 2]) # 6
|