你如何连接和保持列表

时间:2018-05-28 16:04:32

标签: python arrays numpy concatenation

import numpy as np

array = ([a,b,c],[a,b,c])

array2 = ([1,2,3],[1,2,3])

concatenate_arrays = np. concatenate(array,array2)

#expected:[a,1,b,2,c,3]

#i want:[[[a,b,c] [1,2,3]],[[a,b,c] [1,2,3]]]

1 个答案:

答案 0 :(得分:0)

我猜你要搜索的是zip ...

import numpy as np
array = (['a','b','c'],['a','b','c'])
array2 = ([1,2,3],[1,2,3])

np.array(list(zip(array, array2)))

...返回

array([[['a', 'b', 'c'],
        ['1', '2', '3']],

       [['a', 'b', 'c'],
        ['1', '2', '3']]])