Skip to content Skip to sidebar Skip to footer

Concatenate 3D Numpy Arrays By Row

I have the following 2 3D numpy arrays that I want to concatenate. The arrays look like this: a = np.array([[[1,1,1], [2,2,2], [3,3,3]],

Solution 1:

Use np.hstack:

np.hstack([a, b])

Output:

array([[['1', '1', '1'],
        ['2', '2', '2'],
        ['3', '3', '3'],
        ['4', '4', '4'],
        ['5', '5', '5'],
        ['6', '6', '6'],
        ['7', '7', '7'],
        ['8', '8', '8'],
        ['9', '9', '9']],

       [['a', 'a', 'a'],
        ['b', 'b', 'b'],
        ['c', 'c', 'c'],
        ['d', 'd', 'd'],
        ['e', 'e', 'e'],
        ['f', 'f', 'f'],
        ['g', 'g', 'g'],
        ['h', 'h', 'h'],
        ['i', 'i', 'i']]], dtype='<U21')

Post a Comment for "Concatenate 3D Numpy Arrays By Row"