Overview
Masked arrays support most NumPy operations while automatically handling masked values. This page covers arithmetic operations, comparisons, reductions, and other common operations.Arithmetic Operations
Masked arrays support all standard arithmetic operators. The resulting mask is the union of the input masks.Basic Arithmetic
Mask Propagation
When operating on masked arrays, masks are combined:Operations with Scalars
Comparison Operations
Comparison operations return masked boolean arrays.Basic Comparisons
Array Comparisons
Reduction Operations
Reduction operations compute aggregates while excluding masked values.Sum and Product
Mean, Median, and Standard Deviation
Min and Max
Reductions Along Axes
Logical Operations
Logical operations work element-wise on masked boolean arrays.All and Any
Universal Functions (ufuncs)
Most NumPy ufuncs work with masked arrays.Mathematical Functions
Rounding and Clipping
Array Manipulation
Reshaping
Transpose
Concatenation
Filling and Conversion
Filling Masked Values
Compressed (Remove Masked)
Practical Examples
Example 1: Time Series Analysis
Example 2: Image Processing
Example 3: Statistical Analysis
Example 4: Multi-dimensional Operations
Performance Tips
In-Place Operations
Use in-place operations to avoid creating unnecessary copies:
Avoid Loops
Use vectorized operations instead of loops:
Use compressed() for Regular Operations
If you need to perform operations that don’t support masking, use
compressed():See Also
- Overview - Masked arrays concepts
- Creation - Creating masked arrays
numpy.ma.MaskedArray- Base class methods
