HackerRank Sum and Prod problem solution in Python YASH PAL, 31 July 202417 January 2026 HackerRank Sum and Prod problem solution in Python – In this Sum and Prod problem, You are given a 2-D array with dimensions N X M. Your task is to perform the sum tool over axis 0 and then find the products of that result.sumThe 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 default, the axis value is None. Therefore, it performs a sum over all the dimensions of the input array.prodThe prod tool returns the product of array elements over a given axis.import numpy my_array = numpy.array([ [1, 2], [3, 4] ]) print numpy.prod(my_array, axis = 0) #Output : [3 8] print numpy.prod(my_array, axis = 1) #Output : [ 2 12] print numpy.prod(my_array, axis = None) #Output : 24 print numpy.prod(my_array) #Output : 24 By default, the axis value is None. Therefore, it performs the product over all the dimensions of the input array.HackerRank Sum and Prod problem solution in Python 2.import numpy m=map(int,raw_input().split()) n=[] for i in range(m[0]): n.append(map(int,raw_input().split())) print numpy.prod(numpy.sum(n,axis=0))Sum and Prod solution in Python 3.import numpyN, M = map(int, input().split())A = numpy.array([input().split() for _ in range(N)],int)print(numpy.prod(numpy.sum(A, axis=0), axis=0))Problem solution in pypy programming.# Enter your code here. Read input from STDIN. Print output to STDOUTimport numpyN, M = map(int, raw_input().split())myarr = []for _ in range(N): myarr.append(map(int,raw_input().split()))print numpy.prod(numpy.sum(myarr, axis = 0), axis = 0)Problem solution in pypy3 programming.# Enter your code here. Read input from STDIN. Print output to STDOUT import functools n, m = map(int, input().split()) a = [] for _ in range(n): a.append(list(map(int,input().split()))) #print(a) b = [sum(x) for x in zip(*a)] print(functools.reduce(lambda x,y: x*y, b)) coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython