NumPy如何将复数矩阵相乘? [英] How does NumPy multiply matrices of complex numbers?

查看:601
本文介绍了NumPy如何将复数矩阵相乘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试找出 NumPy复数矩阵乘法背后的算法

import numpy as np

A = np.array([[17.+0.j, -3.+0.j],
              [-7.+0.j,  1.+0.j]])

B = np.array([[ 60.+0.j,  -4.+0.j],
              [-12.+0.j,   0.+0.j]])

print(A * B)

它输出:

[[1020.+0.j   12.-0.j]
 [  84.-0.j    0.+0.j]]

标准矩阵乘法有很大的不同,您可以从下面的数字中看到,所以我不知道这是什么正是NumPy做到的:

The result from a standard matrix multiplication is very different, as you can see by the numbers below, so I'm left wondering what it is exactly that NumPy does:

[[1056.+0.j  -68.+0.j]
 [-432.+0.j   28.+0.j]]

我一直在尝试仅使用 for 循环来重现其乘法算法,但我仍然没有找到答案。

I've been trying to reproduce their multiplication algorithm using just for loops but I still haven't found the answer. Any tips?

推荐答案

计算 A * B 时,实际上是在相乘矩阵元素,给您所谓的哈达玛德积。这不是母乳。例如(17. + 0.j)*(60. + 0.j)= 1020. + 0.j ,它是输出中的第一个元素。对于矩阵乘法,请使用 np.dot 或仅使用 @ 运算符,即 A @ B

When you compute A*B it's actually multiplying the matrices elementwise, giving you what is called the hadamard product. It isn't matmul. For example (17.+0.j) * (60.+0.j) = 1020.+0.j, which is the first element in the output. For matrix multiplication use np.dot or simply the @ operator, ie, A@B.

这篇关于NumPy如何将复数矩阵相乘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆