shaoheshaohe 发表于 2020-5-14 08:55:41

Numpy知识点补充:np.vstack()&np.hstack()

np.vstack:按垂直方向(行顺序)堆叠数组构成一个新的数组In:import numpy as npIn:a = np.array([])a.shapeOut:(1, 3)In :b = np.array([])b.shapeOut:(1, 3)In :c = np.vstack((a,b)) # 将两个(1,3)形状的数组按垂直方向叠加print(c)c.shape # 输出形状为(2,3)[ ]Out:(2, 3)In :a = np.array([,,])a.shapeOut:(3, 1)In :b = np.array([,,])b.shapeOut:(3, 1)In :c = np.vstack((a,b))# 将两个(3,1)形状的数组按垂直方向叠加print(c)c.shape # 输出形状为(6,1)[ ]Out:(6, 1)
np.hstack:按水平方向(列顺序)堆叠数组构成一个新的数组In:a = np.array([])a.shapeOut:(1, 3)In :b = np.array([])b.shapeOut:(1, 3)In :c = np.hstack((a,b)) # 将两个(1,3)形状的数组按水平方向叠加print(c)c.shape# 输出形状为(1,6)[]Out:(1, 6)In :a = np.array([,,])a.shapeOut:(3, 1)In :b = np.array([,,])b.shapeOut:(3, 1)In :c = np.hstack((a,b)) 将两个(3,1)形状的数组按水平方向叠加print(c)c.shape# 输出形状为(3,2)[ ]Out:(3, 2)





shaoheshaohe 发表于 2020-5-14 08:55:53

链接:https://www.jianshu.com/p/2469e0e2a1cf
页: [1]
查看完整版本: Numpy知识点补充:np.vstack()&np.hstack()