Source From Here
Question
I have a numpy 2D array [[1,2,3]]. I need to append a numpy 1D array,( say [4,5,6]) to it, so that it becomes [[1,2,3], [4,5,6]]. This is easily possible using lists, where you just call append on the 2D list.
But how do you do it in Numpy arrays? np.concatenate and np.append don't work. they convert the array to 1D for some reason.
How-To
You want np.vstack (Stack arrays in sequence vertically as row wise.):
Question
I have a numpy 2D array [[1,2,3]]. I need to append a numpy 1D array,( say [4,5,6]) to it, so that it becomes [[1,2,3], [4,5,6]]. This is easily possible using lists, where you just call append on the 2D list.
But how do you do it in Numpy arrays? np.concatenate and np.append don't work. they convert the array to 1D for some reason.
How-To
You want np.vstack (Stack arrays in sequence vertically as row wise.):
沒有留言:
張貼留言