Stack arrays in sequence horizontally (column wise). This is equivalent to concatenation along the second axis, except for 1-D arrays where it concatenates along the first axis. Rebuilds arrays divided by `hsplit`. This function makes most sense for arrays with up to 3 dimensi
(tup, *, dtype=None, casting="same_kind")
| 291 | |
| 292 | @array_function_dispatch(_vhstack_dispatcher) |
| 293 | def hstack(tup, *, dtype=None, casting="same_kind"): |
| 294 | """ |
| 295 | Stack arrays in sequence horizontally (column wise). |
| 296 | |
| 297 | This is equivalent to concatenation along the second axis, except for 1-D |
| 298 | arrays where it concatenates along the first axis. Rebuilds arrays divided |
| 299 | by `hsplit`. |
| 300 | |
| 301 | This function makes most sense for arrays with up to 3 dimensions. For |
| 302 | instance, for pixel-data with a height (first axis), width (second axis), |
| 303 | and r/g/b channels (third axis). The functions `concatenate`, `stack` and |
| 304 | `block` provide more general stacking and concatenation operations. |
| 305 | |
| 306 | Parameters |
| 307 | ---------- |
| 308 | tup : sequence of ndarrays |
| 309 | The arrays must have the same shape along all but the second axis, |
| 310 | except 1-D arrays which can be any length. |
| 311 | |
| 312 | dtype : str or dtype |
| 313 | If provided, the destination array will have this dtype. Cannot be |
| 314 | provided together with `out`. |
| 315 | |
| 316 | .. versionadded:: 1.24 |
| 317 | |
| 318 | casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional |
| 319 | Controls what kind of data casting may occur. Defaults to 'same_kind'. |
| 320 | |
| 321 | .. versionadded:: 1.24 |
| 322 | |
| 323 | Returns |
| 324 | ------- |
| 325 | stacked : ndarray |
| 326 | The array formed by stacking the given arrays. |
| 327 | |
| 328 | See Also |
| 329 | -------- |
| 330 | concatenate : Join a sequence of arrays along an existing axis. |
| 331 | stack : Join a sequence of arrays along a new axis. |
| 332 | block : Assemble an nd-array from nested lists of blocks. |
| 333 | vstack : Stack arrays in sequence vertically (row wise). |
| 334 | dstack : Stack arrays in sequence depth wise (along third axis). |
| 335 | column_stack : Stack 1-D arrays as columns into a 2-D array. |
| 336 | hsplit : Split an array into multiple sub-arrays horizontally (column-wise). |
| 337 | |
| 338 | Examples |
| 339 | -------- |
| 340 | >>> a = np.array((1,2,3)) |
| 341 | >>> b = np.array((4,5,6)) |
| 342 | >>> np.hstack((a,b)) |
| 343 | array([1, 2, 3, 4, 5, 6]) |
| 344 | >>> a = np.array([[1],[2],[3]]) |
| 345 | >>> b = np.array([[4],[5],[6]]) |
| 346 | >>> np.hstack((a,b)) |
| 347 | array([[1, 4], |
| 348 | [2, 5], |
| 349 | [3, 6]]) |
| 350 |