- 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
Check the base of a masked array in NumPy
To check the base of masked array data that owns its memory, use the ma.MaskedArray.base attribute in Numpy. Returns dtype for the base element of the subarrays, regardless of their dimension or shape.
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 using the numpy.array() method −
arr = np.array([[35, 85], [67, 33]]) print("Our Array...
", arr)
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 check the base of an array that owns its memory, use the numpy.base attribute. The base of an array that owns its memory is None −
print("
Our Array baseclass
", arr.base)
To check the base of masked array data that owns its memory, use the ma.MaskedArray.base attribute in Numpy −
print("
Our Masked Array baseclass
", maskArr.base)
Example
import numpy as np import numpy.ma as ma arr = np.array([[35, 85], [67, 33]]) print("Our Array...
", arr) # 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 check the base of an array that owns its memory, use the numpy.base attribute # The base of an array that owns its memory is None print("
Our Array baseclass
", arr.base) # To check the base of masked array data that owns its memory, use the ma.MaskedArray.base attribute in Numpy print("
Our Masked Array baseclass
", maskArr.base)
Output
Our Array... [[35 85] [67 33]] Our Masked Array [[35 85] [67 --]] Our Array baseclass None Our Masked Array baseclass [[35 85] [67 33]]
- Related Articles
- Get the datatype 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
- Return element-wise base masked array raised to power from second array in Numpy
- Repeat elements of a masked array in Numpy
- Return the absolute value of a masked Array in NumPy
- Check which element in a masked array is less than the given value in Numpy
- Return the transpose of the masked array in NumPy
- Get the itemsize of the masked array in Numpy
- Return the length of the masked array in Numpy
- Get the Masked Array Dimensions in Numpy
- Check which element in a masked array is equal to a given value in NumPy
- Transform a masked array into a flexibletype array in Numpy
