for example:
import numpy as np
rg = np.random.default_rng(1) # create instance of default random number␣
a = np.floor(10 * rg.random((2, 2)))
b = np.floor(10 * rg.random((2, 2)))
print(a)
print(b)
c = np.column_stack((a, b))
print(c)
result:
a: [[5. 9.]
[1. 9.]] shape: (2, 2)
b: [[3. 4.]
[8. 4.]] shape: (2, 2)
c: [[5. 9. 3. 4.]
[1. 9. 8. 4.]] shape: (2, 4)
for the row_stack:
d = np.row_stack((a, b))
print("d:",d)
result is :
d: [[5. 9.]
[1. 9.]
[3. 4.]
[8. 4.]] shape: (4, 2)
There are other functions similar to these two:
1) np.concatenate((a,b)) or np.vstack((a,b)) or np.r_[a,b]
concatenate rows of a and b
2) np.concatenate((a,b) or np.hstack((a,b)) or np.column_stack((a,b)) or np.c_[a,b]
concatenate columns of
a
and
b