If I start with a 3x4 array and concatenate a 3x1 array, with axis 1, I get a 3x5 array:
In [911]: x = np.arange(12).reshape(3,4)
In [912]: np.concatenate([x,x[:,-1:]], axis=1)
Out[912]:
array([[ 0, 1, 2, 3, 3],
[ 4, 5, 6, 7, 7],
[ 8, 9, 10, 11, 11]])
In [913]: x.shape,x[:,-1:].shape
Out[913]: ((3, 4), (3, 1))
Note that both concatenation inputs have 2 dimensions.
Omit :, and x[:,-1]- form (3) is 1d and therefore the error:
In [914]: np.concatenate([x,x[:,-1]], axis=1)
...
ValueError: all the input arrays must have same number of dimensions
np.append ( , )
return concatenate((arr, values), axis=axis)
, append . 2 . append , .
In [916]: np.append(x, x[:,-1:], axis=1)
Out[916]:
array([[ 0, 1, 2, 3, 3],
[ 4, 5, 6, 7, 7],
[ 8, 9, 10, 11, 11]])
np.hstack , atleast_1d, :
return np.concatenate([np.atleast_1d(a) for a in arrs], 1)
x[:,-1:]. , .
np.column_stack 1. 1d
array(arr, copy=False, subok=True, ndmin=2).T
(3) (3,1).
In [922]: np.array(x[:,-1], copy=False, subok=True, ndmin=2).T
Out[922]:
array([[ 3],
[ 7],
[11]])
In [923]: np.column_stack([x,x[:,-1]])
Out[923]:
array([[ 0, 1, 2, 3, 3],
[ 4, 5, 6, 7, 7],
[ 8, 9, 10, 11, 11]])
"" , np.concatenate. , . ipython ??.
np.concatenate - , , .