首页 > 其他 > 详细

Numpy

时间:2015-11-16 09:22:38      阅读:215      评论:0      收藏:0      [点我收藏+]

 

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: 

 

 

>>>x=np.array([[1,2,3],[4,5,6]],float)# 2 by 3

>>>y=np.array([[1,2],[3,3],[4,5]],float) # 3 by 2
>>>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

Numpy

原文:http://www.cnblogs.com/midforest/p/4968035.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!