[英]Python - How to concatenate more than arrays lists in python?
I have many arrays, let's say 我有很多数组,比方说
X = np.array([1, 2, 3, 4])
Y = np.array([5, 6, 7, 8])
Z = np.array([9, 10, 11, 12])
I want to concatenate them all so I have 我想将它们全部连接起来,所以我有
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Here is what I've tried 这是我尝试过的
arr = X + Y + Z
this doesn't work, here is my result 这不起作用,这是我的结果
>>> print(arr)
[15, 18, 21, 24]
Just the sum of each element at an index i
. 只是索引
i
上每个元素的总和。 Any suggestions? 有什么建议么?
you can use np.concatenate()
你可以使用
np.concatenate()
a = np.concatenate((X, Y, Z))
print(a)
[ 1 2 3 4 5 6 7 8 9 10 11 12]
Use np.concatenate
to combine np arrays: 使用
np.concatenate
合并np数组:
import numpy as np
X = np.array([1, 2, 3, 4])
Y = np.array([5, 6, 7, 8])
Z = np.array([9, 10, 11, 12])
print np.concatenate((X,Y,Z), axis=0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.