NumPy Universal Functions

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=[1,2,3,4,5]
ar2=[10,20,30,40,50]
ar3=[1,1,1,1,1]
# print(ar1)
# print(np.cumprod(ar1))
print(np.cumprod([ar1,ar2,ar3],axis=1))


#print(np.prod([ar1])) # 1*2*3*4*5
#print(np.prod([ar1,ar2])) # 1*2*3*4*5
#print(np.prod([ar1,ar2,ar3],axis=1)) 

# print(ar1)
# print(ar2)
# print(np.cumsum([ar1,ar2],axis=1))
# print(ar1)
# print(np.cumsum(ar1)) # [1,3,]








#print(np.add(ar1,ar2))
#print(np.sum(ar1)) # 1+2+3+4+5
# print(np.sum([ar1,ar2])) # 1+2+3+4+5+10+20+30+40+50
# print(np.sum([ar1,ar2,ar3],axis=1)) 
# def testadd(x,y):
#     return(x+y)

# testadd=np.frompyfunc(testadd,2,1)
# print(testadd(ar1,ar2))
# print(type(testadd))









# ar3=np.add(ar1,ar2)
# print(type(ar3))
# print(type(np.add))
# print(type(np.concatenate))

# print(ar1)
# print(ar2)
# print("-----------------------")
# c=np.add(ar1,ar2)
# print("Addition")
# print(c)
# c=np.multiply(ar1,ar2)
# print("Multiplication")
# print(c)
# c=np.subtract(ar1,ar2)
# print("subtraction")
# print(c)
# c=np.divide(ar1,ar2)
# print("Divide")
# print(c)







#print(type(np.add))
# ar3=np.add(ar1,ar2)
# print(ar3)


# ar3=[]
# for i,j in zip(ar1,ar2):
#     ar3.append(i+j)

# print(ar3)

 

Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review 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 *