一文浅析np.hstack


前言

np.hstack的功能 —— 数组元素的堆叠


一、栗子

import numpy as np

arr1 = [1, 2, 3]
arr2 = [4, 5]
arr3 = [6, 7]
res = np.hstack((arr1, arr2,arr3))
print(res)    # [1 2 3 4 5 6 7]

import numpy as np

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

print(res)

结果为:

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

二、总结

使用np.hstack()可方便进行数组堆叠

猜你喜欢

转载自blog.csdn.net/weixin_43283397/article/details/109645530