Method # 1: Getting the number of zeros using numpy.count_nonzero()

Exit:
initial arrays [1 2 3 4 5 6 0] [0 0 0 0 0 0] Number of nonzeroes in array1: 6 Number of nonzeroes in array2: 0
Method # 2: Using numpy.any ()
# Python code to check if
# all elements in numpy are null
import
numpy as np
ini_array1
=
np.array ([
1
,
2
,
3
,
4
,
5
,
6
,
0
])
ini_array2
= < / code> np.array ([
0
,
0
,
0
,
0
,
0
,
0
])
# printing initial arrays
print
(
"initial arrays"
, ini_array1)
# code to determine if all elements are zero
countzero_in1
=
not
np.
any (ini_array1)
countzero_in2
=
not
np.
any
(ini_array2)
# print result
print
(
"Whole array contains zeroes in array1?:"
, countzero_in1)
print
(
"Whole array contains zeroes in array2?:"
, countzero_in2)
Exit :
initial arrays [1 2 3 4 5 6 0] Whole array contains zeroes in array1?: False Whole array contains zeroes in array2?: True
Since you are interested in learning more about designing data visualizations (by virtue of the fact that you’re reading this book), then chances are good that you have been the reader of other peop...
10/07/2020
This is the first book on synthetic data for deep learning, and its extensive coverage could make this book the standard benchmark for synthetic data for years to come. The book can also serve as an i...
28/08/2021
The ability to identify patterns is an essential component of sensory intelli gent machines. Pattern recognition is therefore an indispensible component of the socalled “Intelligent Control System...
10/07/2020
If you can program, you are ready to grapple with Bayesian statistics. In this book, you'll learn how to solve statistical problems using Python code instead of math formulas, using discrete probabili...
28/08/2021