I have 2 numpy arrays and i want to combine these two array together using extend. eg:
a = [[1,2,3],[4,5,6],[7,8,9]]
b = [[0,0,0],[1,1,1]]
what i want is
c = [[1,2,3],[4,5,6],[7,8,9],[0,0,0],[1,1,1]]
It seems that I cannot use extend as python list. otherwise it will raise AttributeError: 'numpy.ndarray' object has no attribute 'extend' error.
Currently I tried by transforming them into lists :
a_list = a.tolist()
b_list = b.tolist()
a_list.extend(b_list)
c = numpy.array(a_list)
I wonder if any better solution exist?
Use -
np.concatenate((a, b), axis=0)
Or -
np.vstack((a,b))
Or -
a.append(b) # appends in-place, a will get modified directly
Output
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[0, 0, 0],
[1, 1, 1]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With