Numpy
Assume that we have two matrices/arrays x (n by k) and y (k by m); the dot product
will generate a matrix with n by m as shown in the following lines of code:
will generate a matrix with n by m as shown in the following lines of code:
>>>x=np.array([[1,2,3],[4,5,6]],float)# 2 by 3
>>>np.dot(x,y)# 2 by 2
Array([[19.,23.],]43., 53.]])
Alternatively, we could convert arrays into matrices first and then use * of matrix
multiplication as shown in the following lines of code:
>>>x=np.matrix("1,2,3;4,5,6")
>>>y=np.matrix("1,2;3,3;4,5")
>>>x*y
Array([[19., 23.],[43., 53.]])
Actually, we could convert an array into a matrix easily as follows:
>>>x1=np.array([[1,2,3],[4,5,6]],float)
>>>x2=np.matrix(x1) # from array to matrix
>>>x3=np.array(x2) # from matrix to array
浙公网安备 33010602011771号