Python数据分析三剑客:Pandas、Numpy、Matplotlib

Numpy:常用的线性代数计算方法

2018-09-08  本文已影响14人  ACphart


注:以下运算的对象a, b, c均为numpy.ndarray,并称其为numpy数组,简称数组

单个数组运算 a.shape = (4, 6)

两个数组运算

数组自动扩展及变形a.shape=(4, 6), b.shape=(4, 1), c.shape=(1, 6), d.shape=(6,)

三维数组运算

x = [[[1, 1, 1]],
     [[2, 2, 2]]]
a = np.array(x)
w = np.array(x)+1

z = np.array([np.dot(m.T, n) for m, n in zip(a, b)])
z
z.sum(axis=0)/2
array([[[2, 2, 2],
        [2, 2, 2],
        [2, 2, 2]],

       [[6, 6, 6],
        [6, 6, 6],
        [6, 6, 6]]])
array([[ 4.,  4.,  4.],
       [ 4.,  4.,  4.],
       [ 4.,  4.,  4.]])
上一篇 下一篇

猜你喜欢

热点阅读