Skip to content

Element wise division numpy

  • by

In NumPy, you can perform element-wise division on arrays using the / operator or the numpy.divide() function. Element-wise division means that each element in one array is divided by the corresponding element in another array.

Here’s the basic syntax:

result_array = array1 / array2

In this syntax:

  • array1 and array2 are the NumPy arrays you want to divide.
  • / is the operator used for element-wise division.
  • result_array is the resulting NumPy array containing the element-wise division results.

Element wise division numpy example

Simple example code.

import numpy as np

# Create two NumPy arrays
array1 = np.array([10, 20, 30, 40, 50])
array2 = np.array([2, 4, 6, 8, 10])

# Perform element-wise division
result = array1 / array2

print(result)

Output:

Element wise division numpy

In this example, array1 is divided by array2 element-wise, meaning each element in array1 is divided by the corresponding element in array2. The result is a new NumPy array with the element-wise division results.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.