我有两个矩阵。计算总和超过axis=1
。然后我想转置所获得的结果。结果包含在表达式中。您必须是矩阵1的元素,并且2按行逐行计算总和。总和的移调结果
您是否需要转置sum数组还是有其他方法?
matrix1 = [[ 5. 4. 3. 5. 3.]
[ 5. 7. 8. 2. 2.]
[ 8. 2. 4. 0. 3.]
[ 7. 2. 5. 3. 5.]
[ 3. 1. 3. 0. 2.]]
matrix2 = [[ 5. 7. 6. 5. 4.]
[ 3. 45. 2. 3. 4.]
[ 2. 4. 6. 4. 3.]
[ 3. 4. 5. 6. 54.]
[ 4. 3. 6. 7. 5.]]
s_1 = np.array(matrix_1.sum(axis=1))
s_1 = np.array(matrix_2.sum(axis=1))
s_1T = np.transpose(s_1)
s_2T = np.transpose(s_2)
结果:
S_1T
[ 20. 24. 17. 22. 9.]
S_2T
[ 27. 57. 19. 72. 25.]
如何转置阵?使用表达式
FROM
[ 20. 24. 17. 22. 9.]
[ 27. 57. 19. 72. 25.]
TO
[20.
24.
17.
22.
9.]
[27.
57.
19.
72.
25.]
换位阵列:
result = ((matrix_2 - matrix_1)/matrix_1)/((s_2T-s_1T)/s_1T)
您可能是指[[20.] [24.] [17.] [22.] [9.]]? – iced 2015-03-13 11:01:53