一、np.vstack(tup)使用

沿着竖直方向将矩阵堆叠起来。
Note: the arrays must have the same shape along all but the first axis. 除开第一维外,被堆叠的矩阵各维度要一致。
示例代码:

import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
res = np.vstack((arr1, arr2))

结果如下:

array([[1, 2, 3],
       [4, 5, 6]])


二、np.hstack(tup)

沿着水平方向将数组堆叠起来。
Note:
tup : sequence of ndarrays
All arrays must have the same shape along all but the second axis.
示例代码:

import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
res = np.hstack((arr1, arr2))

print res


arr1 = np.array([[1, 2], [3, 4], [5, 6]])
arr2 = np.array([[7, 8], [9, 0], [0, 1]])
res = np.hstack((arr1, arr2))

print res

结果如下:

[1 2 3 4 5 6]

[[1 2 7 8]
 [3 4 9 0]
 [5 6 0 1]]

 

原博:https://blog.csdn.net/u012609509/article/details/70319293

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐