Python Program to Find Numpy Array Length

Write a Python Program to Find the length of a Numpy Array. The numpy module has a len function that returns the array length. In this example, we declared the integer and string array and used the len function to find those lengths.

import numpy as np

intarr = np.array([10, 20, 35, 44, 78, 99, 248])
print("Integer Numpy Array Items = ", intarr)

intarrLength = len(intarr)
print("Integer Numpy Array Length = ", intarrLength)

strarr = np.array(['UK', 'India', 'USA', 'Japan'])
print("String Numpy Array Items = ", strarr)

strarrLength = len(strarr)
print("String Numpy Array Length = ", strarrLength)
Python Program to Find Numpy Array Length 1

This program allows entering the array items and calculates the Numpy Array Length.

import numpy as np

arrList = []
number = int(input("Enter the Total Array Items = "))
for i in range(1, number + 1):
    value = int(input("Enter the %d Array value = " %i))
    arrList.append(value)

intArr = np.array(arrList)
print("Integer Numpy Array Items = ", intArr)

intArrLength = len(intArr)
print("Integer Numpy Array Length = ", intArrLength)

Numpy program output

Enter the Total Array Items = 4
Enter the 1 Array value = 20
Enter the 2 Array value = 90
Enter the 3 Array value = 120
Enter the 4 Array value = 50
Integer Numpy Array Items =  [ 20  90 120  50]
Integer Numpy Array Length =  4