MCPcopy
hub / github.com/numpy/numpy / dstack

Function dstack

numpy/lib/_shape_base_impl.py:656–712  ·  view source on GitHub ↗

Stack arrays in sequence depth wise (along third axis). This is equivalent to concatenation along the third axis after 2-D arrays of shape `(M,N)` have been reshaped to `(M,N,1)` and 1-D arrays of shape `(N,)` have been reshaped to `(1,N,1)`. Rebuilds arrays divided by `dsplit`

(tup)

Source from the content-addressed store, hash-verified

654
655@array_function_dispatch(_dstack_dispatcher)
656def dstack(tup):
657 """
658 Stack arrays in sequence depth wise (along third axis).
659
660 This is equivalent to concatenation along the third axis after 2-D arrays
661 of shape `(M,N)` have been reshaped to `(M,N,1)` and 1-D arrays of shape
662 `(N,)` have been reshaped to `(1,N,1)`. Rebuilds arrays divided by
663 `dsplit`.
664
665 This function makes most sense for arrays with up to 3 dimensions. For
666 instance, for pixel-data with a height (first axis), width (second axis),
667 and r/g/b channels (third axis). The functions `concatenate`, `stack` and
668 `block` provide more general stacking and concatenation operations.
669
670 Parameters
671 ----------
672 tup : sequence of arrays
673 The arrays must have the same shape along all but the third axis.
674 1-D or 2-D arrays must have the same shape.
675
676 Returns
677 -------
678 stacked : ndarray
679 The array formed by stacking the given arrays, will be at least 3-D.
680
681 See Also
682 --------
683 concatenate : Join a sequence of arrays along an existing axis.
684 stack : Join a sequence of arrays along a new axis.
685 block : Assemble an nd-array from nested lists of blocks.
686 vstack : Stack arrays in sequence vertically (row wise).
687 hstack : Stack arrays in sequence horizontally (column wise).
688 column_stack : Stack 1-D arrays as columns into a 2-D array.
689 dsplit : Split array along third axis.
690
691 Examples
692 --------
693 >>> import numpy as np
694 >>> a = np.array((1,2,3))
695 >>> b = np.array((4,5,6))
696 >>> np.dstack((a,b))
697 array([[[1, 4],
698 [2, 5],
699 [3, 6]]])
700
701 >>> a = np.array([[1],[2],[3]])
702 >>> b = np.array([[4],[5],[6]])
703 >>> np.dstack((a,b))
704 array([[[1, 4]],
705 [[2, 5]],
706 [[3, 6]]])
707
708 """
709 arrs = atleast_3d(*tup)
710 if not isinstance(arrs, tuple):
711 arrs = (arrs,)
712 return _nx.concatenate(arrs, 2)
713

Callers 5

test_0D_arrayMethod · 0.90
test_1D_arrayMethod · 0.90
test_2D_arrayMethod · 0.90
test_2D_array2Method · 0.90
test_generatorMethod · 0.90

Calls 1

atleast_3dFunction · 0.90

Tested by 5

test_0D_arrayMethod · 0.72
test_1D_arrayMethod · 0.72
test_2D_arrayMethod · 0.72
test_2D_array2Method · 0.72
test_generatorMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…