- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return element-wise quotient and remainder simultaneously in Python Numpy
To return the element-wise quotient and remainder simultaneously, use the numpy.fmod() method in Python Numpy. Here, the 1st parameter is the Dividend array. The 2nd parameter is the Divisor array.
This is the NumPy implementation of the C library function fmod, the remainder has the same sign as the dividend x1. It is equivalent to the Matlab(TM) rem function and should not be confused with the Python modulus operator x1 % x2.
The condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
Steps
At first, import the required library −
import numpy as np
Create an array. This is the dividend array −
arr = np.array([5, 9, 14, 22, 76, 81, 91])
Display the arrays −
print("Array...
", arr)
Get the type of the arrays −
print("
Our Array type...
", arr.dtype)
Get the dimensions of the Arrays −
print("
Our Array Dimension...
",arr.ndim)
Get the shape of the Arrays −
print("
Our Array Shape...
",arr.shape)
Divisor array −
divisor = np.array([3, 7, 3, 3, 2, 7, 7])
To return the element-wise quotient and remainder simultaneously, use the numpy.fmod() method. Here, the 1st parameter is the Dividend array. The 2nd parameter is the Divisor array −
print("
Result...
",np.divmod(arr, divisor))
Example
import numpy as np # Create an array # This is the dividend array arr = np.array([5, 9, 14, 22, 76, 81, 91]) # Display the array print("Array...
", arr) # Get the type of the array print("
Our Array type...
", arr.dtype) # Get the dimensions of the Array print("
Our Array Dimension...
",arr.ndim) # Get the shape of the Array print("
Our Array Shape...
",arr.shape) # Divisor array divisor = np.array([3, 7, 3, 3, 2, 7, 7]) # To return the element-wise quotient and remainder simultaneously, use the numpy.fmod() method in Python Numpy # Here, the 1st parameter is the Dividend array # The 2nd parameter is the Divisor array print("
Result...
",np.divmod(arr, divisor))
Output
Array... [ 5 9 14 22 76 81 91] Our Array type... int64 Our Array Dimension... 1 Our Array Shape... (7,) Result... (array([ 1, 1, 4, 7, 38, 11, 13]), array([2, 2, 2, 1, 0, 4, 0]))
- Related Articles
- Return the element-wise remainder of division in Numpy
- Return the element-wise remainder of division with fmod() operation in Numpy
- Return the element-wise remainder of division with modulo operation in Numpy
- Divide a given scalar element with masked array elements and return arrays with Quotient and Remainder in NumPy
- Divide masked array elements by a given scalar element and return arrays with Quotient and Remainder in NumPy
- Return element-wise string multiple concatenation in Numpy
- Compare two arrays and return the element-wise minimum in Numpy
- Compare two arrays and return the element-wise maximum in Numpy
- Return the reciprocal of the argument element-wise in Numpy
- Compare two arrays and return the element-wise maximum ignoring NaNs in Numpy
- Compare two Numpy arrays and return the element-wise maximum with fmax()
- Compare two Numpy arrays and return the element-wise minimum ignoring NaNs
- Compare two Numpy arrays and return the element-wise minimum with fmin()
- Return element-wise string concatenation for two arrays of string in Numpy
- Return element-wise title cased version of string or Unicode in Numpy
