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

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *