In this article, you will learn how to get the number of rows and columns in the NumPy array.
The syntax of finding the array size is numpy.size( _, _ ). The first argument takes the array and the second argument uses 0 or 1 for array rows and height respectively. Let’s check out the code for finding the rows and columns in the NumPy array.
Code:
import numpy
# Create new 2D NumPy array
my_array = numpy.array([[0, 1, 3], [5, 7, 9]])
# Calculate number of Rows
Rows = numpy.size(my_array, 0)
# Calculate number of Columns
Columns = numpy.size(my_array, 1)
print("The Generated 2D NumPy Array: ", my_array)
print("The Total Rows of NumPy Array: ", Rows)
print("The Total Columns of NumPy Array: ", Columns)
Output:
The Generated 2D NumPy Array: [[0 1 3]
[5 7 9]]
The Total Rows of NumPy Array: 2
The Total Columns of NumPy Array: 3
References:
Check out the NumPy original documentation for a brief description.