- 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
Get the Imaginary part from the masked array in Numpy
To get the imaginary part from the masked array, use the ma.MaskedArray.imag attribute in Numpy. This property is a view on the imaginary part of this MaskedArray.
A mask is either nomask, indicating that no value of the associated array is invalid, or an array of booleans that determines for each element of the associated array whether the value is valid or not.
Steps
At first, import the required library −
import numpy as np import numpy.ma as ma
Creating an array of complex number elements using the numpy.array() method −
arr = np.array([68.+4.j , 49.+7.j , 120.+2.j , 64.+0.j]) print("Array..
",arr) print("
Get the imaginary part",arr.imag) print("
Get the datatype
",arr.dtype)
Create a masked array and mask some of them as invalid −
maskArr = ma.masked_array(arr, mask =[False, False, True, False]) print("
Our Masked Array
", maskArr) 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("
Elements in the Masked Array...
",maskArr.size)
To get the imaginary part from the masked array, use the ma.MaskedArray.imag attribute in Numpy −
print("
Get the imaginary part...
",maskArr.imag)
Example
import numpy as np import numpy.ma as ma # Creating an array of complex number elements using the numpy.array() method arr = np.array([68.+4.j , 49.+7.j , 120.+2.j , 64.+0.j]) print("Array..
",arr) print("
Get the imaginary part",arr.imag) print("
Get the datatype
",arr.dtype) print("
The number of elements
",arr.size) # Create a masked array and mask some of them as invalid maskArr = ma.masked_array(arr, mask =[False, False, True, False]) print("
Our Masked Array
", maskArr) 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("
Elements in the Masked Array...
",maskArr.size) # To get the imaginary part from the masked array, use the ma.MaskedArray.image attribute in Numpy print("
Get the imaginary part...
",maskArr.imag)
Output
Array.. [ 68.+4.j 49.+7.j 120.+2.j 64.+0.j] Get the imaginary part [4. 7. 2. 0.] Get the datatype complex128 The number of elements 4 Our Masked Array [(68+4j) (49+7j) -- (64+0j)] Our Masked Array type... complex128 Our Masked Array Dimensions... 1 Our Masked Array Shape... (4,) Elements in the Masked Array... 4 Get the imaginary part... [4.0 7.0 -- 0.0]
- Related Articles
- Get the Masked Array Dimensions in Numpy
- Get the itemsize of the masked array in Numpy
- Get the datatype of a masked array in NumPy
- Get the fill value of the masked array in Numpy
- Get the current shape of the Masked Array in Numpy
- Get the number of elements of the Masked Array in Numpy
- Get the information about the memory layout of the masked array in Numpy
- Count the non-masked elements of the masked array in Numpy
- Remove axes of length one from the masked array in Numpy
- Swift Program to get the imaginary part of the given complex number
- C++ Program to get the imaginary part of the given complex number
- Sort the masked array in-place in NumPy
- Return specified diagonals from a masked array 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
