How do I know the number of rows and columns of an array in the Python language?
How do I know the number of rows and columns of an array in the Python language?
depends on what you mean by "array": The python language itself, pure, does not have a specific array structure. You can use lists within lists, but there is no way to determine size without iterating and counting elements from each list.
A very common alternative for manipulation of arrays is the numpy library. It is not part of python and needs to be installed separately, however, it greatly facilitates the use of arrays and their operations. If you are using numpy, you can use the shape
attribute:
import numpy
m = numpy.array([[1, 2, 3], [10, 15, 20]])
print(m.shape)
This will print the dimensions of the numpy array (called array):
(2, 3)