All the functions are written in Python except np.concatenate
. With an IPython shell you just use ??
.
If not, here's a summary of their code:
vstack
concatenate([atleast_2d(_m) for _m in tup], 0)
i.e. turn all inputs in to 2d (or more) and concatenate on first
hstack
concatenate([atleast_1d(_m) for _m in tup], axis=<0 or 1>)
colstack
transform arrays with (if needed)
array(arr, copy=False, subok=True, ndmin=2).T
append
concatenate((asarray(arr), values), axis=axis)
In other words, they all work by tweaking the dimensions of the input arrays, and then concatenating on the right axis. They are just convenience functions.
And newer np.stack
:
arrays = [asanyarray(arr) for arr in arrays]
shapes = set(arr.shape for arr in arrays)
result_ndim = arrays[0].ndim + 1
axis = normalize_axis_index(axis, result_ndim)
sl = (slice(None),) * axis + (_nx.newaxis,)
expanded_arrays = [arr[sl] for arr in arrays]
concatenate(expanded_arrays, axis=axis, out=out)
That is, it expands the dims of all inputs (a bit like np.expand_dims
), and then concatenates. With axis=0
, the effect is the same as np.array
.
hstack
documentation now adds:
The functions concatenate
, stack
and
block
provide more general stacking and concatenation operations.
np.block
is also new. It, in effect, recursively concatenates along the nested lists.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…