在python中连接几个np数组

mot*_*aha 5 python numpy

我有几个颠簸的数组,我想连接它们.我在用np.concatenate((array1,array2),axis=1).我现在的问题是我想让数组的数量参数化,我写了这个函数

x1=np.array([1,0,1])
x2=np.array([0,0,1])
x3=np.array([1,1,1])  

def conc_func(*args):
    xt=[]
    for a in args:
        xt=np.concatenate(a,axis=1)
    print xt
    return xt

xt=conc_func(x1,x2,x3)
Run Code Online (Sandbox Code Playgroud)

这个函数返回([1,1,1]),我希望它返回([1,0,1,0,0,1,1,1,1]).我尝试添加for循环里面np.concatenate这样

xt =np.concatenate((for a in args: a),axis=1)
Run Code Online (Sandbox Code Playgroud)

但我收到语法错误.我既不能使用也不能延伸,因为我必须处理numpy arrays而不是处理lists.有人可以帮忙吗?

提前致谢

unu*_*tbu 10

concatenate可以接受一系列数组,例如args:

In [11]: args = (x1, x2, x3)

In [12]: xt = np.concatenate(args)

In [13]: xt
Out[13]: array([1, 0, 1, 0, 0, 1, 1, 1, 1])
Run Code Online (Sandbox Code Playgroud)

顺便说一句,虽然axis=1有效,但输入都是一维数组(所以它们只有一个0轴).因此,默认情况下,完全使用axis=0或省略更有意义.axisaxis=0