简体   繁体   English

python中两个arrays的列的相关性

[英]Correlation of columns of two arrays in python

I have two arrays: 900x421 and 900x147.我有两个 arrays:900x421 和 900x147。 I need to correlate all columns from these arrays so that the output is 421x147.我需要关联这些 arrays 中的所有列,以便 output 为 421x147。 In Matlab function corr() does it, but I can't find a function that does the same in python.在 Matlab function corr()中执行此操作,但我找不到在 function 中执行相同操作的 function 执行相同操作的 function

the numpy.corrcoef function is the way to go. numpy.corrcoef function 是通往 go 的方法。 You need both arguments x and y to be of the same shape.您需要 arguments xy具有相同的形状。 You can do so by concatenate the two arrays.您可以通过连接两个 arrays 来实现。 Let's say arr1 is of shape 900x421 and arr2 is of shape 900x147.假设arr1的形状为 900x421, arr2的形状为 900x147。 You can do the following您可以执行以下操作

import numpy as np
two_arrays = np.concatenate((arr1, arr2), axis=1) # 900x568
corr = np.corrcoef(two_arrays) # 568x568 array
desired_output = corr[0:421][422:]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM