MCPcopy Create free account
hub / github.com/numpy/numpy / stack

Function stack

numpy/core/shape_base.py:373–457  ·  view source on GitHub ↗

Join a sequence of arrays along a new axis. The ``axis`` parameter specifies the index of the new axis in the dimensions of the result. For example, if ``axis=0`` it will be the first dimension and if ``axis=-1`` it will be the last dimension. .. versionadded:: 1.10.0 Par

(arrays, axis=0, out=None, *, dtype=None, casting="same_kind")

Source from the content-addressed store, hash-verified

371
372@array_function_dispatch(_stack_dispatcher)
373def stack(arrays, axis=0, out=None, *, dtype=None, casting="same_kind"):
374 """
375 Join a sequence of arrays along a new axis.
376
377 The ``axis`` parameter specifies the index of the new axis in the
378 dimensions of the result. For example, if ``axis=0`` it will be the first
379 dimension and if ``axis=-1`` it will be the last dimension.
380
381 .. versionadded:: 1.10.0
382
383 Parameters
384 ----------
385 arrays : sequence of array_like
386 Each array must have the same shape.
387
388 axis : int, optional
389 The axis in the result array along which the input arrays are stacked.
390
391 out : ndarray, optional
392 If provided, the destination to place the result. The shape must be
393 correct, matching that of what stack would have returned if no
394 out argument were specified.
395
396 dtype : str or dtype
397 If provided, the destination array will have this dtype. Cannot be
398 provided together with `out`.
399
400 .. versionadded:: 1.24
401
402 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
403 Controls what kind of data casting may occur. Defaults to 'same_kind'.
404
405 .. versionadded:: 1.24
406
407
408 Returns
409 -------
410 stacked : ndarray
411 The stacked array has one more dimension than the input arrays.
412
413 See Also
414 --------
415 concatenate : Join a sequence of arrays along an existing axis.
416 block : Assemble an nd-array from nested lists of blocks.
417 split : Split array into a list of multiple sub-arrays of equal size.
418
419 Examples
420 --------
421 >>> arrays = [np.random.randn(3, 4) for _ in range(10)]
422 >>> np.stack(arrays, axis=0).shape
423 (10, 3, 4)
424
425 >>> np.stack(arrays, axis=1).shape
426 (3, 10, 4)
427
428 >>> np.stack(arrays, axis=2).shape
429 (3, 4, 10)
430

Callers 10

test_start_stop_arrayMethod · 0.90
test_base_arrayMethod · 0.90
test_stop_base_arrayMethod · 0.90
test_start_stop_arrayMethod · 0.90
test_start_stop_arrayMethod · 0.90
test_stackFunction · 0.90
test_stack_out_and_dtypeFunction · 0.90
test_stack_1dMethod · 0.50
test_stack_masksMethod · 0.50
test_stack_ndMethod · 0.50

Calls 2

normalize_axis_indexFunction · 0.90
asanyarrayFunction · 0.85

Tested by 10

test_start_stop_arrayMethod · 0.72
test_base_arrayMethod · 0.72
test_stop_base_arrayMethod · 0.72
test_start_stop_arrayMethod · 0.72
test_start_stop_arrayMethod · 0.72
test_stackFunction · 0.72
test_stack_out_and_dtypeFunction · 0.72
test_stack_1dMethod · 0.40
test_stack_masksMethod · 0.40
test_stack_ndMethod · 0.40