首页 > 解决方案 > 如何连接numpy数组?

问题描述

如何连接numpy数组?

我想连接所有 numpy 数组。

例如,有一些 numpy 数组如下

a = numpy.array([1,2,3])
b = numpy.array([4,5,6])
c = numpy.array([7,8,9])

将它们全部连接起来。

我们需要一个额外的空变量。

tot = numpy.concatenate(tot, a)
tot = numpy.concatenate(tot, b)
tot = numpy.concatenate(tot, c)

如何声明全部为空变量?(如果数组太多?)

标签: pythonnumpy

解决方案


你需要它们在一个元组中:

>>> tot = numpy.concatenate((a,b,c))
>>> tot
array([1, 2, 3, 4, 5, 6, 7, 8, 9])

推荐阅读