HackerRank Python

Sum and Prod in Python – HackerRank Solution

Sum The sum tool returns the sum of array elements over a given axis.  import numpy my_array = numpy.array([ [1, 2], [3, 4] ]) print numpy.sum(my_array, axis = 0) #Output : [4 6] print numpy.sum(my_array, axis = 1) #Output : [3 7] print numpy.sum(my_array, axis = None) #Output : 10 print numpy.sum(my_array) #Output : 10 By …

Sum and Prod in Python – HackerRank Solution Read More »

Array Mathematics in Python – HackerRank Solution

 Basic mathematical functions operate element-wise on arrays. They are available both as operator overloads and as functions in the NumPy module. import numpy a = numpy.array([1,2,3,4], float) b = numpy.array([5,6,7,8], float) print a + b #[ 6. 8. 10. 12.] print numpy.add(a, b) #[ 6. 8. 10. 12.] print a – b #[-4. -4. -4. …

Array Mathematics in Python – HackerRank Solution Read More »