a = np.random.randn(5) print(a) ## [-1.17124494 -1.0144042 -1.81090015 0.06239375 0.80871696] print(a.T) ## [ 1.27831203 -0.02878799 -0.18697777 0.22739936 -0.53940577] ## a为rank1 vector, 无法进行outer product计算 b = np.random.randn(5, 1) print(b) # b为column vector # [[-0.76206967] # [ 0.38957009] # [-0.60387659] # [ 1.32058981] # [ 0.28547156]] c = np.random.randn(1, 5) print(c) # c为row vector # [[-0.12683617 -0.07037879 0.68081286 -0.93557581 1.1530988 ]] dot = np.dot(b,c) outer = np.outer(b,c) print(dot.shape) # (5, 5) print(outer.shape) # (5, 5) # 可见进行outer product运算的结果相同
numpy的rank1 array与矩阵内积外积计算
猜你喜欢
转载自blog.csdn.net/weixin_41947081/article/details/80750359
今日推荐
周排行