w3resource logo
Python Exercises

Python NumPy: Get the element-wise remainder of an array of division

Python NumPy Math, Statistics, Trigonometry and Linear algebra: Exercise-6 with Solution

Write a Python program to get the element-wise remainder of an array of division.

Sample Solution:-

Python Code:

import numpy as np
x = np.arange(7)
print("Original array:")
print(x)
print("Element-wise remainder of division:")
print(np.remainder(x, 5))

Sample Output:

Original array:                                                        
[0 1 2 3 4 5 6]                                                        
Element-wise remainder of division:                                    
[0 1 2 3 4 0 1]

Python Code Editor:

import numpy as np
x = np.arange(7)
print("Original array:")
print(x)
print("Element-wise remainder of division:")
print(np.remainder(x, 5))

Improve this sample solution and post your code through Disqus