在Python中使用scipy/numpy添加和乘法两个矩阵
我正在尝试使用scipy和numpy来进行矩阵的加法和乘法。
我有两个矩阵“a”和“b”。我的目标是将“a”和“b”相加,并把结果存储到一个矩阵“c”中。
另外,我还想将“a”和“b”相乘,并把结果存储到一个矩阵“d”中。
在Scipy/Numpy中有没有这样的函数可以使用呢?
非常感谢!
1 个回答
14
矩阵相乘:
a = numpy.matrix(a)
b = numpy.matrix(b)
c = a+b
d = a*b
数组相乘(使用 map 操作符的乘法):
a = numpy.array(a)
b = numpy.array(b)
c = a+b
d = a*b