numpy.
hstack
(tup)[source]
Stack arrays in sequence horizontally (column wise).html
Take a sequence of arrays and stack them horizontally to make a single array. Rebuild arrays divided by hsplit
.git
This function continues to be supported for backward compatibility, but you should prefer np.concatenate
or np.stack
. The np.stack
function was added in NumPy 1.10.github
Parameters: | tup : sequence of ndarrayside
|
---|---|
Returns: | stacked : ndarrayui
|
See alsocode
stack
vstack
dstack
concatenate
hsplit
block
Notesorm
Equivalent to np.concatenate(tup, axis=1)
if tup contains arrays that are at least 2-dimensional.htm
Examples
>>> a = np.array((1,2,3)) >>> b = np.array((2,3,4)) >>> np.hstack((a,b)) array([1, 2, 3, 2, 3, 4]) >>> a = np.array([[1],[2],[3]]) >>> b = np.array([[2],[3],[4]]) >>> np.hstack((a,b)) array([[1, 2], [2, 3], [3, 4]])官網:https://docs.scipy.org/doc/numpy/reference/generated/numpy.hstack.html函數具體實現:https://github.com/numpy/numpy/blob/v1.13.0/numpy/core/shape_base.py#L239-L293