mindspore.numpy.corrcoef

mindspore.numpy.corrcoef(x, y=None, rowvar=True, dtype=None)[source]

Returns Pearson product-moment correlation coefficients.

Please refer to the documentation for cov for more detail. The relationship between the correlation coefficient matrix, R, and the covariance matrix, C, is \(R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }\) The values of R are between -1 and 1, inclusive.

Note

Currently, complex numbers are not supported.

Parameters
  • x (Union[int, float, bool, tuple, list, Tensor]) – A 1-D or 2-D array containing multiple variables and observations. Each row of x represents a variable, and each column a single observation of all those variables. Also see rowvar below.

  • y (Union[int, float, bool, tuple, list, Tensor], optional) – An additional set of variables and observations.

  • rowvar (bool, optional) – If rowvar is True (default), then each row represents a variable, with observations in the columns. Otherwise, the relationship is transposed: each column represents a variable, while the rows contain observations.

  • dtype (mindspore.dtype, optional) – Data-type of the result. By default, the return data-type will have at least float32 precision.

Returns

Tensor, The correlation coefficient matrix of the variables.

Raises
  • TypeError – if the inputs have types not specified above.

  • ValueError – if x and y have wrong dimensions.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> output = np.corrcoef([[2., 3., 4., 5.], [0., 2., 3., 4.], [7., 8., 9., 10.]])
>>> print(output)
[[1.         0.9827076  1.        ]
[0.9827077  0.99999994 0.9827077 ]
[1.         0.9827076  1.        ]]