In: Computer Science
PYTHON
head_count = [np.equal(x3,i).sum() for i in range(1,18)]
head_count
The question is: how could I write code that does the same as np.equal(x3,i).sum() without using Numpy?
# Python Program illustrating
# numpy.sum() method
import numpy as np
# 1D array
arr = [20, 2, .2, 10, 4]
print("\nSum of arr : ", np.sum(arr))
print("Sum of arr(uint8) : ", np.sum(arr, dtype =
np.uint8))
print("Sum of arr(float32) : ", np.sum(arr, dtype =
np.float32))
print ("\nIs np.sum(arr).dtype == np.uint : ",
np.sum(arr).dtype == np.uint)
print ("Is np.sum(arr).dtype == np.float : ",
np.sum(arr).dtype == np.float)
------------------------------------------------------
# Python Program illustrating
# numpy.sum() method
import numpy as np
# 2D array
arr = [[14, 17, 12, 33, 44],
[15, 6, 27, 8, 19],
[23, 2, 54, 1, 4,]]
print("\nSum of arr : ", np.sum(arr))
print("Sum of arr(uint8) : ", np.sum(arr, dtype =
np.uint8))
print("Sum of arr(float32) : ", np.sum(arr, dtype =
np.float32))
print ("\nIs np.sum(arr).dtype == np.uint : ",
np.sum(arr).dtype == np.uint)
print ("Is np.sum(arr).dtype == np.uint : ",
np.sum(arr).dtype == np.float)
-------------------------------------------------------------------------------------------------------------------------------------