- 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 an empty masked array of the given shape where all the data are masked in Numpy
To return an empty masked array of the given shape and dtype where all the data are masked, use the ma.masked_all() method in Python Numpy. The 1st parameter sets the shape of the required MaskedArray.
A masked array is the combination of a standard numpy.ndarray and a mask. 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
Return an empty masked array of the given shape and dtype where all the data are masked using the ma.masked_all() method −
arr = ma.masked_all((5, 5))
Displaying our array −
print("Array...
",arr)
Get the datatype −
print("
Array datatype...
",arr.dtype)
Get the dimensions of the Array −
print("
Array Dimensions...
",arr.ndim)
Get the shape of the Array −
print("
Our Array Shape...
",arr.shape)
Get the number of elements of the Array −
print("
Elements in the Array...
",arr.size)
Example
# Python ma.MaskedArray - Return an empty masked array of the given shape where all the data are masked import numpy as np import numpy.ma as ma # To return an empty masked array of the given shape and dtype where all the data are masked, use the ma.masked_all() method in Python Numpy # The 1st parameter sets the shape of the required MaskedArray arr = ma.masked_all((5, 5)) # Displaying our array print("Array...
",arr) # Get the datatype print("
Array datatype...
",arr.dtype) # Get the dimensions of the Array print("
Array Dimensions...
",arr.ndim) # Get the shape of the Array print("
Our Array Shape...
",arr.shape) # Get the number of elements of the Array print("
Elements in the Array...
",arr.size)
Output
Array... [[-- -- -- -- --] [-- -- -- -- --] [-- -- -- -- --] [-- -- -- -- --] [-- -- -- -- --]] Array datatype... float64 Array Dimensions... 2 Our Array Shape... (5, 5) Elements in the Array... 25
- Related Articles
- Return an empty masked array of the given shape and dtype where all the data are masked in Numpy
- Return all the non-masked data as a 1-D array in Numpy
- Return a masked array containing the same data but with a new shape in Numpy
- Empty masked array with the properties of an existing array in Numpy
- Get the current shape of the Masked Array in Numpy
- Return the transpose of the masked array in NumPy
- Return the length of the masked array in Numpy
- Copy and return all the elements of a masked array in Numpy
- Return the underlying data as a view of the masked array in Numpy
- Return a copy of the masked array in NumPy
- Return the mask of a masked array in Numpy
- Return the variance of the masked array elements along given axis in Numpy
- Return an array formed from the elements of a masked array at the given indices in NumPy
- Return the average of the masked array elements in Numpy
- Return the variance of the masked array elements in Numpy
