stack

stack(arrays: Tuple[array, ...] | List[array], /, *, axis: int = 0) array

Joins a sequence of arrays along a new axis.

Parameters:
  • arrays (Union[Tuple[array, ...], List[array]]) – input arrays to join. Each array must have the same shape.

  • axis (int) – axis along which to join the arrays. Providing an axis specifies the index of the new axis in the shape of the result. For example, if axis is 0, the new axis must be the first dimension and the output array must have shape (N, A, B, C); if axis is 1, the new axis will be the second dimension and the output array will have shape (A, N, B, C); and, if axis is -1, the new axis will be the last dimension and the output array will have shape (A, B, C, N). A valid axis must be an integer on the interval [-N, N), where N is the number of axes in x. If an axis is specified as a negative integer, the function must determine the axis along which to perform the operation by counting backward from the last axis (where -1 refers to the last axis). If provided an invalid axis, the function must raise an exception. Default: 0.

Returns:

out (array) – an output array. The returned array must have N+1 axes, where N is the number of axes in x. If the input arrays have different data types, normal Type Promotion Rules must apply. If the input arrays have the same data type, the output array must have the same data type as the input arrays.

Notes

  • This specification leaves type promotion between data type families (i.e., intxx and floatxx) unspecified and thus implementation-defined.