Contents
Kinh Nghiệm về Python list all zeros Đầy đủ Mới Nhất
Bạn đang tìm kiếm từ khóa Python list all zeros Đầy đủ được Update vào lúc : 2022-01-06 10:29:00 . Với phương châm chia sẻ Kinh Nghiệm về trong nội dung bài viết một cách Chi Tiết Mới Nhất. Nếu sau khi tìm hiểu thêm nội dung bài viết vẫn ko hiểu thì hoàn toàn có thể lại Comment ở cuối bài để Mình lý giải và hướng dẫn lại nha.
Thủ Thuật Hướng dẫn Python list all zeros Mới Nhất
You đang tìm kiếm từ khóa Python list all zeros được Update vào lúc : 2022-01-06 10:29:06 . Với phương châm chia sẻ Mẹo về trong nội dung nội dung bài viết một cách Chi Tiết 2022. Nếu sau khi tìm hiểu thêm nội dung nội dung bài viết vẫn ko hiểu thì hoàn toàn hoàn toàn có thể lại phản hồi ở cuối bài để Ad lý giải và hướng dẫn lại nha.
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. Lets discuss few ways to solve the above task.
Method #1: Getting count of Zeros using numpy.count_nonzero()
Python3
# Python code to demonstrate
# to count the number of elements
# in numpy which are zero
import numpy as np
ini_array1 = np.array([1, 2, 3, 4, 5, 6, 0])
ini_array2 = np.array([0, 0, 0, 0, 0, 0])
# printing initial arrays
print(“initial arrays”, ini_array1)
print(ini_array2)
# code to find whether all elements are zero
countzero_in1 = np.count_nonzero(ini_array1)
countzero_in2 = np.count_nonzero(ini_array2)
# printing result
print(“Number of non-zeroes in array1 : “, countzero_in1)
print(“Number of non-zeroes in array2 : “, countzero_in2)
Output:
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 numpy.any()
Python3
# Python code to check that whether
# all elements in numpy are zero
import numpy as np
ini_array1 = np.array([1, 2, 3, 4, 5, 6, 0])
ini_array2 = np.array([0, 0, 0, 0, 0, 0])
# printing initial arrays
print(“initial arrays”, ini_array1)
# code to find whether all elements are zero
countzero_in1 = not np.any(ini_array1)
countzero_in2 = not np.any(ini_array2)
# printing result
print(“Whole array contains zeroes in array1 ?: “, countzero_in1)
print(“Whole array contains zeroes in array2 ?: “, countzero_in2)
Output:
initial arrays [1 2 3 4 5 6 0]
Whole array contains zeroes in array1 ?: False
Whole array contains zeroes in array2 ?: True
Article Tags :
Python
Python numpy-program
Read Full Article
Reply
2
0
Chia sẻ
Chia Sẻ Link Cập nhật Python list all zeros miễn phí
Bạn vừa tìm hiểu thêm Post Với Một số hướng dẫn một cách rõ ràng hơn về Review Python list all zeros tiên tiến và phát triển và tăng trưởng nhất và Chia SẻLink Tải Python list all zeros Free.
Thảo Luận vướng mắc về Python list all zeros
Nếu sau khi đọc nội dung nội dung bài viết Python list all zeros vẫn chưa hiểu thì hoàn toàn hoàn toàn có thể lại Comments ở cuối bài để Admin lý giải và hướng dẫn lại nha
#Python #list #zeros
Review Python list all zeros Đầy đủ ?
Bạn vừa đọc tài liệu Với Một số hướng dẫn một cách rõ ràng hơn về Review Python list all zeros Đầy đủ tiên tiến và phát triển nhất
Chia Sẻ Link Down Python list all zeros Đầy đủ miễn phí
Người Hùng đang tìm một số trong những Chia Sẻ Link Cập nhật Python list all zeros Đầy đủ Free.
Giải đáp vướng mắc về Python list all zeros Đầy đủ
Nếu sau khi đọc nội dung bài viết Python list all zeros Đầy đủ vẫn chưa hiểu thì hoàn toàn có thể lại Comment ở cuối bài để Mình lý giải và hướng dẫn lại nha
#Python #list #zeros #Đầy #đủ