Python Practice › NumPy Programs › Program 79

Is an array empty?

EasyNumPy Programs · 79 of 100

Write a NumPy program to check whether an array is empty.

Advertisement
Input
[4, 8, 0], []
Output
[4 8 0] Array is not empty
[] Array is empty

Approach

  1. Check a.size == 0.

Solution

Python
import numpy as npfor a in [np.array([4, 8, 0]), np.array([])]:    print(a, "Array is empty" if a.size == 0 else "Array is not empty")
Output
[4 8 0] Array is not empty
[] Array is empty

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs

Leave a Comment