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

标签 python arrays numpy matrix-multiplication idl-programming-language

我正在寻找与 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/

相关文章:

javascript - 如何使用 lodash 复制数组?

java - Java 中使用 BigDecimal 的二维数组

arrays - 具有巨大多维数组的 malloc,无法用于神经科学模拟

python - numpy中有没有一种方法可以测试矩阵是否是单一的

python - 规范化来自各种 "image"对象的 numpy 数组

python - 在 Google Analytics API 中使用多个表达式

python - 用 1D numpy 数组创建 2D

python - Twisted 和 libtorrent——我需要担心阻塞吗?

python - 计算方差图像python

python - 在Python中读取Pandas数据框中的 float 时出现问题