- 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 datatype of a masked array in NumPy
To get the datatype of the masked array, use the ma.MaskedArray.dtype attribute in Numpy. The data type object describes how the bytes in the fixed-size block of memory corresponding to an array item should be interpreted.
NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more. It supports a wide range of hardware and computing platforms, and plays well with distributed, GPU, and sparse array libraries.
Masked arrays are arrays that may have missing or invalid entries. The numpy.ma module provides a nearly work-alike replacement for numpy that supports data arrays with masks.
Steps
At first, import the required library −
import numpy as np import numpy.ma as ma
Create an array with using the numpy.array() method −
arr = np.array([[35, 85], [67, 33]]) print("Our Array...
", arr)
Get the datatype of the array −
print("
Our Array type...
", arr.dtype)
Create a masked array and mask some of them as invalid −
maskArr = ma.masked_array(arr, mask =[[0, 0], [ 0, 1]]) print("
Our Masked Array
", maskArr)
To get the datatype of the masked array, use the ma.MaskedArray.dtype attribute in Numpy −
print("
Our Masked Array type...
", maskArr.dtype)
Example
import numpy as np import numpy.ma as ma # Create a numpy array using the numpy.array() method arr = np.array([[35, 85], [67, 33]]) print("Our Array...
", arr) # Get the datatype of the arrat print("
Our Array type...
", arr.dtype) # Create a masked array and mask some of them as invalid maskArr = ma.masked_array(arr, mask =[[0, 0], [ 0, 1]]) print("
Our Masked Array
", maskArr) # To get the datatype of the masked array, use the ma.MaskedArray.dtype attribute in Numpy print("
Our Masked Array type...
", maskArr.dtype)
Output
Our Array... [[35 85] [67 33]] Our Array type... int64 Our Masked Array [[35 85] [67 --]] Our Masked Array type... int64
- Related Articles
- Get the Masked Array Dimensions in Numpy
- Get the itemsize of the masked array in Numpy
- Return the default fill value for a masked array with float datatype in Numpy
- Return the default fill value for a masked array with complex datatype 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 Imaginary part from the masked array in Numpy
- Get the information about the memory layout of the masked array in Numpy
- Check the base of a masked array in NumPy
- Return a copy of the masked array in NumPy
- Dump a pickle of the masked array in NumPy
- Return the mask of a masked array in Numpy
- Count the non-masked elements of the masked array in Numpy
- Get the mod of every element of a masked Array with a scalar value in NumPy
