使用scipy / numpy在python中添加2个矩阵和乘以2矩阵

时间:2011-05-23 02:53:22

标签: python math matrix numpy scipy

我正在尝试使用scipy和numpy来执行矩阵加法和乘法。

我有2个矩阵“a”和“b”。我的目标是将“a”和“b”加在一起,并将结果存储到矩阵“c”

此外,我想将“a”和“b”相乘并存储到矩阵“d”中。

在Scipy / Numpy中是否有类似的功能?

非常感谢。

1 个答案:

答案 0 :(得分:12)

矩阵乘法:

a = numpy.matrix(a)
b = numpy.matrix(b)
c = a+b
d = a*b

数组乘法(map operator.mul):

a = numpy.array(a)
b = numpy.array(b)
c = a+b
d = a*b