Array concatenation capabilities of numpy
np.concatenate(<tuple-arrays>[, <axis>])
You can concatenate arrays together with the concatenate()
function
- You need to pass the arrays in concatenating order as a tuple
- If you pass
axis=None
it will flatten the arrays
a = np.array([
[4, 8],
[6, 1]
])
b = np.array([
[3, 5],
[7, 2],
])
np.concatenate((a, b))
# Out:
array([[4, 8],
[6, 1],
[3, 5],
[7, 2]])
np.concatenate((a, b), axis=None)
# Out:
array([4, 8, 6, 1, 3, 5, 7, 2])
You can use this concatenation api
shortcuts:
hstack()
: Concatenate horizontallyvstack()
: Concatenate vertically
np.hstack((a, b))
# Out:
array([[4, 8, 3, 5],
[6, 1, 7, 2]])
np.vstack((b, a))
# Out:
array([[3, 5],
[7, 2],
[4, 8],
[6, 1]])