胖胖的球球

导航

矩阵乘法__(学生入门版)

#coding=utf-8
import numpy as np
a=np.array([[1,2,3],[4,5,6],[7,8,9]])
b = a.copy()
c=a+b
print a
print b
print c
print """ *********************************"""
a1=np.array([[1],[4],[7]])
print a1
b = np.array([[1,2,3],[4,5,6],[7,8,9]])
print b
c1=a1+b
print c1

"""
[[1 2 3]
 [4 5 6]
 [7 8 9]]
[[1 2 3]
 [4 5 6]
 [7 8 9]]
[[ 2  4  6]
 [ 8 10 12]
 [14 16 18]]
 *********************************
[[1]
 [4]
 [7]]
[[1 2 3]
 [4 5 6]
 [7 8 9]]
[[ 2  3  4]
 [ 8  9 10]
 [14 15 16]]

"""
print """ **************no.dot*******************"""

d=np.array([[1,2,3],[4,5,6],[7,8,9]])
e = a.copy()
f=np.dot(d,e)
print d
print e
print f
print """ *********************************"""
a1=np.array([[1],[4],[7]])
print a1
b = np.array([[1,2,3],[4,5,6],[7,8,9]])
print b
c1=a1*b
print c1

"""
[[1 2 3]
 [4 5 6]
 [7 8 9]]
[[1 2 3]
 [4 5 6]
 [7 8 9]]
[[ 30  36  42]
 [ 66  81  96]
 [102 126 150]]
 *********************************
[[1]
 [4]
 [7]]
[[1 2 3]
 [4 5 6]
 [7 8 9]]
[[ 1  2  3]
 [16 20 24]
 [49 56 63]]
"""


print """ 实践应用中用到的"""
xiangmu_a=[1,2,3,4,1]
xiangmua=np.array(xiangmu_a)
print xiangmua
xiangmu_b=[[1,2],[3,4],[4,5],[5,6],[6,7]]
xiangmub=np.array(xiangmu_b)
print xiangmub
print np.dot(xiangmua,xiangmub)
"""
执行结果分别为:
[1 2 3 4 1]
[[1 2]
 [3 4]
 [4 5]
 [5 6]
 [6 7]]
 
[45 56]


"""




xiangmu_a=[0 ,0 ,0 ,0 ,1 ,0]
xiangmua=np.array(xiangmu_a)
print xiangmua
xiangmu_b=[[ 0.5 , 0.16666667],[0,0.33333333],[ 0.5,0.16666667],[0,0.08333333],[0, 0.08333333],[ 0,0.16666667]]
xiangmub=np.array(xiangmu_b)
print xiangmub
print np.dot(xiangmua,xiangmub)

 

posted on 2018-12-06 10:09  胖胖的球球  阅读(215)  评论(0编辑  收藏  举报