有没有办法关联 n 个数组?
Is there a way to correlate n arrays?
我需要关联 n 个我组合成一个列表的数组,如下所示:
array_corr = [array([a1]), array([a2]), array([a3]), .... array([an])]
corr_mat = np.corrcoef([array_corr])
但我收到错误消息:
operands could not be broadcast together.
所有数组的大小都相同。我不明白错误的来源。
我希望输出是一个 nxn 矩阵,因为有 n 个数组。
只需使 array_corr
成为一个纯 numpy 二维数组并将其发送到 np.corrcoef
而不带括号(您正在以这种方式创建一个只有一个矩阵元素的列表):
array_corr = np.array([
[1,2,3,4,5],
[1,6,3,3,5],
[1,2,9,4,3],
[2,1,3,8,5],
[6,6,2,6,5],
])
corr_mat = np.corrcoef(array_corr)
corr_mat
returns:
array([[ 1. , 0.40555355, 0.30460385, 0.74074375, -0.18257419],
[ 0.40555355, 1. , -0.05764881, -0.11092108, 0.07404361],
[ 0.30460385, -0.05764881, 1. , 0.16777868, -0.92688 ],
[ 0.74074375, -0.11092108, 0.16777868, 1. , 0.1040313 ],
[-0.18257419, 0.07404361, -0.92688 , 0.1040313 , 1. ]])
我需要关联 n 个我组合成一个列表的数组,如下所示:
array_corr = [array([a1]), array([a2]), array([a3]), .... array([an])]
corr_mat = np.corrcoef([array_corr])
但我收到错误消息:
operands could not be broadcast together.
所有数组的大小都相同。我不明白错误的来源。
我希望输出是一个 nxn 矩阵,因为有 n 个数组。
只需使 array_corr
成为一个纯 numpy 二维数组并将其发送到 np.corrcoef
而不带括号(您正在以这种方式创建一个只有一个矩阵元素的列表):
array_corr = np.array([
[1,2,3,4,5],
[1,6,3,3,5],
[1,2,9,4,3],
[2,1,3,8,5],
[6,6,2,6,5],
])
corr_mat = np.corrcoef(array_corr)
corr_mat
returns:
array([[ 1. , 0.40555355, 0.30460385, 0.74074375, -0.18257419],
[ 0.40555355, 1. , -0.05764881, -0.11092108, 0.07404361],
[ 0.30460385, -0.05764881, 1. , 0.16777868, -0.92688 ],
[ 0.74074375, -0.11092108, 0.16777868, 1. , 0.1040313 ],
[-0.18257419, 0.07404361, -0.92688 , 0.1040313 , 1. ]])