mindspore.numpy.corrcoef
- mindspore.numpy.corrcoef(x, y=None, rowvar=True, dtype=None)[源代码]
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.
说明
Currently, complex numbers are not supported.
- 参数
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. Default:
None
.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. Default:True
.dtype (
mindspore.dtype
, optional) – Data-type of the result. By default, the return data-type will have at least float32 precision. Default:None
.
- 返回
Tensor, The correlation coefficient matrix of the variables.
- 异常
TypeError – If the inputs have types not specified above.
ValueError – If x and y have wrong dimensions.
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> 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. ]]