Arithmetic Operations in NumPy

Machine Learning courses with 100+ Real-time projects Start Now!!

Program 1

# Difference between copy and view
# digonal function
#Arithmetic operations beetween  two array

import numpy as np

# Rules of Arithmetic operations in numpy array
# 1. Shape of Arrays must be same
  #     or 
# 2. Second Array must have atleast one dimension and 
# the number of element should be same as first array
        # or 
# 3. Second array having one element 
# ar1=np.array([[1,2,3],[4,5,6]])
# ar2=np.array([[1,2,3],[4,5,6]])
# print(ar1 )
# print()
# print(ar2)
# print("Addition: ")
# ar3=np.add(ar1,ar2)
# print(ar3)
# print("------------------------------")
# print("subtraction: ")
# ar3=np.subtract(ar1,ar2)
# print(ar3)
# print("------------------------------")
# print("Multiply: ")
# ar3=np.multiply(ar1,ar2)
# print(ar3)

# print("Divide: ")
# ar3=np.divide(ar1,ar2)
# print(ar3)

# ar1=np.array([[100,200,300],[45,55,600]])
# print(ar1)
# print()
# ar2=np.mod(ar1,10)
# print(ar2)

# ar1=np.array([[1,2,3],[4,5,6]])
# ar2=np.power(ar1,2)
# print(ar1)
# print()
# print(ar2)

# ar1=np.array([[1,2,3],[4,5,6]])
# ar2=np.array(100)
# print(ar1.shape)
# print(ar2.shape)
# ar3=np.add(ar1,ar2)
# print(ar1)
# print("-------------------------------'")
# print(ar2)
# print("-------------------------------'")
# print(ar3)
# print(ar1.shape)
# print(ar2.shape)



# ar=np.array([[1,2,3,10],[4,5,6,10],[7,8,9,10],[10,11,12,13]])
# print(ar)
# print(ar.shape)
# print(ar.diagonal())





















# ar1=np.array([10,20,30,40,50,60])
# ar2=ar1.view()

# ar1[0]=500
# print(ar1)
# print("---------------------------------------")
# print(ar2)

# ar2[1]=700
# print("******************************")
# print(ar1)
# print("---------------------------------------")
# print(ar2)

# print("Base of Array1:  ",ar1.base)
# print("Base of Array2:  ",ar2.base)

# ar1=np.array([10,20,30,40,50,60])
# ar2=ar1.copy()
# print(ar1.base)
# print("---------------------------------------")
# print(ar2.base)

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience 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 *