Arithmetic Operations on Numpy arrays

Perform arithmetic operations on Numpy arrays using the sum(), subtract(), multiply(), and divide() methods. Let us see the operations one by one:

  • Add Numpy Arrays
  • Subtract Numpy Arrays
  • Multiply Numpy Arrays
  • Divide Numpy Arrays

Add Numpy arrays

To add the elements of NumPy arrays, the sum() method is used. It adds each and every element of both arrays and displays the result in a new array.

Let us see the following examples to add arrays:

  • Add the elements of Numpy arrays
  • Add column values using the axis parameter
  • Add individual array values using the axis parameter

Example1: Add the elements of Numpy arrays

Output

Example2: Add column values using the axis parameter

Output

Example 3: Add individual array values using the axis parameter

Output

Subtract Numpy arrays

Use the subtract() method to subtract one array from another. It subtracts and displays the result in a new array. Let us see an example to subtract NumPy arrays:

Output

Multiply Numpy arrays

Use the multiply() method to multiply elements of one array to another. It multiplies and displays the result in a new array. Let us see an example to multiply NumPy arrays:

Output

Divide Numpy arrays

The divide() method divides elements of one array with elements of another. It divides and displays the result in a new array. Let us see an example to divide NumPy arrays:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.

For Videos, Join Our YouTube Channel: Join Now


Read More:

Difference between Numpy arrays
Scalar operations on Numpy arrays
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading