# Get the itemsize of the masked array in Numpy

NumpyServer Side ProgrammingProgramming

#### Python Data Science basics with Numpy, Pandas and Matplotlib

Most Popular

63 Lectures 6 hours

#### Data Analysis using NumPy and Pandas

19 Lectures 8 hours

#### Numpy with Python

Most Popular

12 Lectures 3 hours

To get the itemsize of the Masked Array, use the ma.MaskedArray.itemsize attribute in Numpy. 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

Create a numpy array using the numpy.array() method −

arr = np.array([[35, 85], [67, 33]])
print("Array...\n", arr)
print("\nArray type...\n", arr.dtype)
print("\nArray itemsize...\n", arr.itemsize)

Get the dimensions of the Array −

print("Array Dimensions...\n",arr.ndim)


Create a masked array and mask some of them as invalid −

maskArr = ma.masked_array(arr, mask =[[0, 0], [ 0, 1]])
print("\nOur Masked Array type...\n", maskArr.dtype)

Get the dimensions of the Masked Array −

print("\nOur Masked Array Dimensions...\n",maskArr.ndim)


To get the itemsize of the Masked Array, use the ma.MaskedArray.itemsize attribute in Numpy −

print("\nOur Masked Array itemsize...\n", maskArr.itemsize)

## 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("Array...\n", arr)
print("\nArray type...\n", arr.dtype)
print("\nArray itemsize...\n", arr.itemsize)

# Get the dimensions of the Array
print("Array Dimensions...\n",arr.ndim)

# Create a masked array and mask some of them as invalid

# Get the dimensions of the Masked Array

# To get the itemsize of the Masked Array, use the ma.MaskedArray.itemsize attribute in Numpy
print("\nOur Masked Array itemsize...\n", maskArr.itemsize)

## Output

Array...
[[35 85]
[67 33]]

Array type...
int64

Array itemsize...
8
Array Dimensions...
2

8