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

28th Nov 2020, 1:50 PM
SURAJ KUMAR
5 Réponses
+ 1
Thanks ...actually i have just started data science with python ....so i am confused
28th Nov 2020, 2:06 PM
SURAJ KUMAR
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())
28th Nov 2020, 1:54 PM
SURAJ KUMAR
0
Sorry i did not write the code
28th Nov 2020, 1:55 PM
SURAJ KUMAR
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
28th Nov 2020, 2:00 PM
Steven M
Steven M - avatar
0
No worries, have fun and good luck
28th Nov 2020, 2:18 PM
Steven M
Steven M - avatar