- 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
Multiply the fractional part of two Numpy arrays with a scalar value
To return the fractional and integral parts of array values, use the numpy.modf() method in Python Numpy. Multiply the fractional values using the index 0 values. The fractional and integral parts are negative if the given number is negative.
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
Creating two 2D numpy arrays using the array() method −
arr1 = np.array([1.7, 20.4, 100.8, 45.8, -22.7, np.nan, np.inf]) arr2 = np.array([5.1, 41.2, 120.4, 30.4, -69.6, np.nan, np.inf])
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)
To return the fractional and integral parts of array values, use the numpy.modf() method in Python Numpy. Multiply the fractional values using the index 0 values −
print("
Result...
",np.modf(arr1[0]*arr2[0]))
Example
import numpy as np # Creating two 2D numpy arrays using the array() method arr1 = np.array([1.7, 20.4, 100.8, 45.8, -22.7, np.nan, np.inf]) arr2 = np.array([5.1, 41.2, 120.4, 30.4, -69.6, np.nan, np.inf]) # 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) # To return the fractional and integral parts of array values, use the numpy.modf() method in Python Numpy # Multiply the fractional values using the index 0 values print("
Result...
",np.modf(arr1[0]*arr2[0]))
Output
Array 1... [ 1.7 20.4 100.8 45.8 -22.7 nan inf] Array 2... [ 5.1 41.2 120.4 30.4 -69.6 nan inf] Our Array 1 type... float64 Our Array 2 type... float64 Our Array 1 Dimensions... 1 Our Array 2 Dimensions... 1 Result... (0.6699999999999999, 8.0)
- Related Articles
- Multiply each element of a masked Array by a scalar value in-place in Numpy
- Return the fractional and integral parts of a value in Numpy
- Add every element of a masked Array with a scalar value in NumPy
- Return the common filling value of two masked arrays in Numpy
- Get the mod of every element of a masked Array with a scalar value in NumPy
- Get the mod of a scalar value with every element of a masked Array in NumPy
- Extract the fractional and integral parts of a specific array value in Numpy
- Divide a scalar value into every element of a masked Array with __truediv__() in NumPy
- Divide every element of a masked Array into a scalar value with __rtruediv__() in NumPy
- Add a scalar value with each element of a masked Array in-place in Numpy
- Get the mod of every element of a masked Array with a scalar value using __imod__() in Numpy
- Divide a given scalar element with masked array elements and return arrays with Quotient and Remainder in NumPy
- Subtract a scalar value from every element of a masked Array in NumPy
- Divide a scalar value into every element of a masked Array in NumPy
- Matrix product of two arrays in Numpy
