numpy.ma.cov#
- ma.cov(x,y=None,rowvar=True,bias=False,allow_masked=True,ddof=None)[source]#
Estimate the covariance matrix.
Except for the handling of missing data this function does the same as
numpy.cov. For more details and examples, seenumpy.cov.By default, masked values are recognized as such. Ifx andy have thesame shape, a common mask is allocated: if
x[i,j]is masked, theny[i,j]will also be masked.Settingallow_masked to False will raise an exception if values aremissing in either of the input arrays.- Parameters:
- xarray_like
A 1-D or 2-D array containing multiple variables and observations.Each row ofx represents a variable, and each column a singleobservation of all those variables. Also seerowvar below.
- yarray_like, optional
An additional set of variables and observations.y has the sameshape asx.
- rowvarbool, optional
Ifrowvar is True (default), then each row represents avariable, with observations in the columns. Otherwise, the relationshipis transposed: each column represents a variable, while the rowscontain observations.
- biasbool, optional
Default normalization (False) is by
(N-1), whereNis thenumber of observations given (unbiased estimate). Ifbias is True,then normalization is byN. This keyword can be overridden bythe keywordddofin numpy versions >= 1.5.- allow_maskedbool, optional
If True, masked values are propagated pair-wise: if a value is maskedinx, the corresponding value is masked iny.If False, raises aValueError exception when some values are missing.
- ddof{None, int}, optional
If not
Nonenormalization is by(N-ddof), whereNisthe number of observations; this overrides the value implied bybias. The default value isNone.
- Raises:
- ValueError
Raised if some values are missing andallow_masked is False.
See also
Examples
>>>importnumpyasnp>>>x=np.ma.array([[0,1],[1,1]],mask=[0,1,0,1])>>>y=np.ma.array([[1,0],[0,1]],mask=[0,0,1,1])>>>np.ma.cov(x,y)masked_array(data=[[--, --, --, --], [--, --, --, --], [--, --, --, --], [--, --, --, --]],mask=[[ True, True, True, True], [ True, True, True, True], [ True, True, True, True], [ True, True, True, True]],fill_value=1e+20,dtype=float64)