Python | Check if all values in numpy are zero
Given a numpy array, the task is to check whether the numpy array contains all zeroes or not. Let’s discuss few ways to solve the above task.
Method #1: Getting count of Zeros using
initial arrays [1 2 3 4 5 6 0] [0 0 0 0 0 0] Number of non-zeroes in array1 : 6 Number of non-zeroes in array2 : 0
Method #2: Using
initial arrays [1 2 3 4 5 6 0] Whole array contains zeroes in array1 ?: False Whole array contains zeroes in array2 ?: True
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course