gpt4 book ai didi

python - IDL # 运算符的 Python numpy 等价物是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 11:52:19 25 4
gpt4 key购买 nike

我正在寻找与 IDL 等效的 Python numpy # 运算符(operator)。这是# 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 ]]

B = [[ 1.          0.          0.        ]
[ 0.62692564 0.77418869 0.08715574]]

另外,numpy.dot(A,B) 导致 ValueError: matrices are not aligned

最佳答案

阅读关于 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)

给予

[[ 3  4  5]
[ 9 14 19]
[15 24 33]]

关于python - IDL # 运算符的 Python numpy 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23128788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com