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

Function dstack

numpy/lib/shape_base.py:660–715  ·  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

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

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