numpy.ma.correlate — NumPy v2.6.dev0 Manual

ma.correlate(a, v, mode='valid', propagate_mask=True)

[source]

#

Cross-correlation of two 1-dimensional sequences.

Parameters:a, varray_likeInput sequences.

mode{‘valid’, ‘same’, ‘full’}, optionalRefer to the np.convolve docstring. Note that the default is ‘valid’, unlike

convolve

, which uses ‘full’.

propagate_maskboolIf True, then a result element is masked if any masked element contributes towards it. If False, then a result element is only masked if no non-masked element contribute towards it

Returns:outMaskedArrayDiscrete cross-correlation of a and v.

Examples

Basic correlation:

>>> a=np.ma.array([1,2,3])>>> v=np.ma.array([0,1,0])>>> np.ma.correlate(a,v,mode='valid')masked_array(data=[2], mask=[False], fill_value=999999)Correlation with masked elements:

>>> a=np.ma.array([1,2,3],mask=[False,True,False])>>> v=np.ma.array([0,1,0])>>> np.ma.correlate(a,v,mode='valid',propagate_mask=True)masked_array(data=[--], mask=[ True], fill_value=999999, dtype=int64)Correlation with different modes and mixed array types:

>>> a=np.ma.array([1,2,3])>>> v=np.ma.array([0,1,0])>>> np.ma.correlate(a,v,mode='full')masked_array(data=[0, 1, 2, 3, 0], mask=[False, False, False, False, False], fill_value=999999)