什么是Python numpy等价的IDL操作符?

2024-04-26 22:51:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我在寻找与IDL操作符等价的Pythonnumpy。 以下是# operator的作用:

Computes array elements by multiplying the columns of the first array by the rows of the second array. The second array must have the same number of columns as the first array has rows. The resulting array has the same number of columns as the first array and the same number of rows as the second array.

下面是我正在处理的numpy数组:

A = [[ 0.9826128   0.          0.18566662]
     [ 0.          1.          0.        ]
     [-0.18566662  0.          0.9826128 ]]

以及

^{pr2}$

另外,numpy.dot(A,B)会产生{}。在


Tags: columnsofthenumpynumberbyasarray
2条回答

阅读IDL关于矩阵乘法定义的注释,似乎他们使用了与其他人相反的符号:

IDL’s convention is to consider the first dimension to be the column and the second dimension to be the row

因此,可以通过相当奇怪的外观来实现:

numpy.dot(A.T, B.T).T

根据它们的示例值:

import numpy as np
A =  np.array([[0, 1, 2], [3, 4, 5]])
B = np.array([[0, 1], [2, 3], [4, 5]])
C = np.dot(A.T, B.T).T
print(C)

给予

^{pr2}$

如果我是对的,你想要matrix multiplication。在

相关问题 更多 >