Why is does count() yield the same result as sum()?

In the project Detecting Product Defects with Probability (Probability for Datascience), in task 13 it is asked to calculate the number of values above 10 in a certain array.
I used np.count_nonzero(array>=10) but the hint tab suggests to use sum(array >= 10). Why do the two functions yield the same result?

Link: https://www.codecademy.com/paths/data-science-inf/tracks/dsf-statistics-fundamentals-for-data-science/modules/dsf-probability-for-data-science/projects/product-defects

Both np.count_nonzero(array>=10) and sum(array >= 10) will yield the same result because both functions are counting the number of elements that are greater than or equal to 10 in the array. np.count_nonzero() will count the number of non-zero elements in the array, and sum() will add up all the elements in the array that are greater than or equal to 10. Since the elements being counted are all greater than or equal to 10, the result of both functions will be the same.

hope this helps! :slight_smile: