- 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 base masked array raised to power from second array in Numpy
To return element-wise base array raised to power from second array, use the MaskedArray.power() method in Python Numpy.
The where parameter is a condition 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.
The out parameter 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.
Steps
At first, import the required library −
import numpy as np import numpy.ma as ma
Create an array with int elements using the numpy.array() method −
arr = np.array([93, 33, 76, 73, 88, 51, 62, 45, 67]) print("Array...
", arr)
Create a masked array and mask some of them as invalid −
maskArr = ma.masked_array(arr, mask =[ 0, 0, 0, 0, 1, 0, 0, 1, 1]) print("
Our Masked Array...
", maskArr)
Get the type of the masked array −
print("
Our Masked Array type...
", maskArr.dtype)
Get the dimensions of the Masked Array −
print("
Our Masked Array Dimensions...
",maskArr.ndim)
Get the shape of the Masked Array −
print("
Our Masked Array Shape...
",maskArr.shape)
Get the number of elements of the Masked Array −
print("
Number of elements in the Masked Array...
",maskArr.size)
Set the power array −
arrPower = [2, 3, 4, 2, 4, 3, 5, 3, 2]
To return element-wise base array raised to power from second array, use the MaskedArray.power() method −
resArr = np.ma.power(maskArr, arrPower) print("
Resultant Array..
.", resArr)
Example
import numpy as np import numpy.ma as ma # Create an array with int elements using the numpy.array() method arr = np.array([93, 33, 76, 73, 88, 51, 62, 45, 67]) print("Array...
", arr) # Create a masked array and mask some of them as invalid maskArr = ma.masked_array(arr, mask =[ 0, 0, 0, 0, 1, 0, 0, 1, 1]) print("
Our Masked Array...
", maskArr) # Get the type of the masked array print("
Our Masked Array type...
", maskArr.dtype) # Get the dimensions of the Masked Array print("
Our Masked Array Dimensions...
",maskArr.ndim) # Get the shape of the Masked Array print("
Our Masked Array Shape...
",maskArr.shape) # Get the number of elements of the Masked Array print("
Number of elements in the Masked Array...
",maskArr.size) # Set the power array arrPower = [2, 3, 4, 2, 4, 3, 5, 3, 2] # To return element-wise base array raised to power from second array, use the MaskedArray.power() method in Python Numpy resArr = np.ma.power(maskArr, arrPower) print("
Resultant Array..
.", resArr)
Output
Array... [93 33 76 73 88 51 62 45 67] Our Masked Array... [93 33 76 73 -- 51 62 -- --] Our Masked Array type... int64 Our Masked Array Dimensions... 1 Our Masked Array Shape... (9,) Number of elements in the Masked Array... 9 Resultant Array.. . [8649 35937 33362176 5329 -- 132651 916132832 -- --]
- Related Articles
- Set the first array elements raised to powers from second array element-wise in Numpy
- Return the base 10 logarithm of the input array element-wise in Numpy
- Return each element of the masked array rounded in Numpy
- Return specified diagonals from a masked array in NumPy
- Return the bases when first array elements are raised to powers from second array in Python
- Subtract every element from a scalar value and return a new masked Array in NumPy
- Return the truth value of an array equal to another element-wise in Numpy
- Return array of indices of the maximum values from a masked array in NumPy
- Return array of indices of the minimum values from a masked array in NumPy
- Return the element-wise square-root of a complex type array in Numpy
- Return the non-negative square-root of an array element-wise in Numpy
- Check the base of a masked array in NumPy
- Convert masked array element to int Type in NumPy
- Return the truth value of an array not equal to another element-wise in Numpy
- Create a new array from the masked array and return a new reference in Numpy
