Python进行矩阵运算

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38455576/article/details/78557643

入门神经网络过程中遇到以下计算:

(1)  (1,-1,0,0.5)'+0.905*(1,-2,1.5,0)'

Python中编程计算如下:

import numpy as np
a=np.array([[1],[-2],[1.5],[0]])*0.905
b=np.array([[1],[-1],[0],[0.5]])
c=a+b
print (c)

最终计算结果为:

[[ 1.905 ]
 [-2.81  ]
 [ 1.3575]
 [ 0.5   ]]


(2)   (1.905,-2.81,1.3575,0.5)*(1,-0.5,-1.5)'

Python中编程计算如下:

import numpy as np
a=np.mat([1.905,-2.81,1.3575,0.5])
b=np.mat([[1],[-0.5],[-2],[-1.5]])
c=a*b
print (c)

最终计算结果为:

[[-0.155]]



猜你喜欢

转载自blog.csdn.net/qq_38455576/article/details/78557643