- 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
True Divide arguments element-wise in Numpy
To true divide arguments element-wise, use the numpy.true_divide() method in Python Numpy. The arr1 is considered Dividend array. The arr2 is considered Divisor array.
The out is a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
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 two 2D arrays −
arr1 = np.array([[14, 28, 56], [84, 56, 112]]) arr2 = np.array([[7, 14, 21], [28, 35, 56]])
Display the arrays −
print("Array 1...
", arr1) print("
Array 2...
", arr2)
Get the type of the arrays −
print("
Our Array 1 type...
", arr1.dtype) print("
Our Array 2 type...
", arr2.dtype)
Get the dimensions of the Arrays −
print("
Our Array 1 Dimensions...
",arr1.ndim) print("
Our Array 2 Dimensions...
",arr2.ndim)
Get the shape of the Arrays −
print("
Our Array 1 Shape...
",arr1.shape) print("
Our Array 2 Shape...
",arr2.shape)
To true divide arguments element-wise, use the numpy.true_divide() method in Python Numpy. The arr1 is considered Dividend array. The arr2 is considered Divisor array −
print("
Result...
",np.true_divide(arr1, arr2))
Example
import numpy as np # Create two 2D arrays arr1 = np.array([[14, 28, 56], [84, 56, 112]]) arr2 = np.array([[7, 14, 21], [28, 35, 56]]) # Display the arrays print("Array 1...
", arr1) print("
Array 2...
", arr2) # Get the type of the arrays print("
Our Array 1 type...
", arr1.dtype) print("
Our Array 2 type...
", arr2.dtype) # Get the dimensions of the Arrays print("
Our Array 1 Dimensions...
",arr1.ndim) print("
Our Array 2 Dimensions...
",arr2.ndim) # Get the shape of the Arrays print("
Our Array 1 Shape...
",arr1.shape) print("
Our Array 2 Shape...
",arr2.shape) # To true divide arguments element-wise, use the numpy.true_divide() method in Python Numpy # The arr1 is considered Dividend array # The arr2 is considered Divisor array print("
Result...
",np.true_divide(arr1, arr2))
Output
Array 1... [[ 14 28 56] [ 84 56 112]] Array 2... [[ 7 14 21] [28 35 56]] Our Array 1 type... int64 Our Array 2 type... int64 Our Array 1 Dimensions... 2 Our Array 2 Dimensions... 2 Our Array 1 Shape... (2, 3) Our Array 2 Shape... (2, 3) Result... [[2. 2. 2.66666667] [3. 1.6 2. ]]
- Related Articles
- True Divide arguments element-wise and display the result in a different type in Numpy
- Subtract arguments element-wise in Numpy
- Divide arguments element-wise and display the result in a different type in Numpy
- Add arguments element-wise with different shapes in Numpy
- Multiply arguments element-wise with different shapes in Numpy
- Subtract arguments element-wise with different shapes in Numpy
- Add arguments element-wise and display the result in a different type in Numpy
- Subtract arguments element-wise and display the result in a different type in Numpy
- Return element-wise True where signbit is set (less than zero) in Numpy
- Return True if two Numpy arrays are element-wise equal within a tolerance
- Test element-wise for NaN in Numpy
- True Divide each element of a masked Array by a scalar value in-place in Numpy
- Return element-wise string multiple concatenation in Numpy
- Calculate the absolute value element-wise in Numpy
- Compute the bit-wise NOT of an array element-wise in Numpy
