Universal Functions in NumPy
Machine Learning courses with 100+ Real-time projects Start Now!!
Program 1
# Universal Functions in Numpy
#Universal Functions are NumPy functions that we use on the ndarray object.
# Its also know as ufuncs
# import numpy as np
# ar1=[10,20,30,40,50]
# ar2=[1,2,3,4,5] # 1, 2 6,24 ,120
# ar3=[1,1,1,1,1]
#print(np.cumprod(ar2))
#print(np.prod([ar1,ar2],axis=1))
#print(np.cumsum([ar1,ar2],axis=1))
# print(np.add(ar1,ar2))
# print("---------------------------------------------------")
# print(np.sum([ar1,ar2,ar3],axis=1))
# def testmultiply(x,y):
# return x*y
# # # def testadd(x, y):
# # # return x+y
# testmultiply=np.frompyfunc(testmultiply,2,1)
# print(testmultiply([1, 2, 3, 4], [1,2, 3, 4]))
# testadd = np.frompyfunc(testadd, 2, 1)
# print(testadd([10, 20, 30, 40], [1,2, 3, 4]))
# a = [10, 20, 30, 40]
# b = [ 3,4,5,6]
# c=np.add(a,b)
# print(c)
# c=np.multiply(a,b)
# print(c)
# c=np.subtract(a,b)
# print(c)
# c=np.divide(a,b)
# print(c)
#c = []
# for i, j in zip(a, b):
# c.append(i + j)
# print(c)
If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

