加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 13:42:00 所属栏目:Python 来源:网络整理
导读:我正在寻找相当于 IDL#运算符的Python numpy. 这是 # 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 ar
我正在寻找相当于 IDL#运算符的Python numpy.
这是 # 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:矩阵未对齐.

解决方法

阅读有关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]]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读