0
What is the use of sum in this code
The above code is for the question to find the number of height greater than 188cm
5 Answers
+ 1
Thanks ...actually i have just started data science with python ....so i am confused
0
import numpy as np
heights = [189, 170, 189, 163, 183, 171, 185, 168, 173, 183, 173, 173, 175, 178, 183, 193, 178, 173, 174, 183, 183, 180, 168, 180, 170, 178, 182, 180, 183, 178, 182, 188, 175, 179, 183, 193, 182, 183, 177, 185, 188, 188, 182, 185, 191]
heights_arr = np.array(heights)
print((heights_arr > 188).sum())
0
Sorry i did not write the code
0
It is finding each element that is greater than 188, and it is keeping a running tally of each. Basically it is adding or counting each entry above 188. That is what sum is doing here
0
No worries, have fun and good luck