参考网址:
http://www.cnblogs.com/begtostudy/archive/2010/08/03/1790935.html
b=np.arange(15)
print(b)
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]
b.reshape(3,5)
Out[32]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
c=np.zeros((4,5))
print (c)
[[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]]
d=np.ones((5,7))
print (d)
[[ 1. 1. 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1. 1. 1.]]
e=np.add(c,np.arange(20).reshape(4,5))
print (e)
[[ 0. 1. 2. 3. 4.]
[ 5. 6. 7. 8. 9.]
[ 10. 11. 12. 13. 14.]
[ 15. 16. 17. 18. 19.]]
f=np.dot(e,d)
print (f)
[[ 10. 10. 10. 10. 10. 10. 10.]
[ 35. 35. 35. 35. 35. 35. 35.]
[ 60. 60. 60. 60. 60. 60. 60.]
[ 85. 85. 85. 85. 85. 85. 85.]]
如果还不明白,举个简单的列子
t1=np.ones((2,2))
t2=np.arange(4).reshape(2,2)
t3=np.dot(t1,t2)
print (t3)
[[ 2. 4.]
[ 2. 4.]]
即
[[ 1*0+1*2. 1*1+1*3.]
[ 2. 4.]]
numpy.linalg中有标准的矩阵运算