numpy.dsplit

numpy.dsplit(ary, indices_or_sections)

Split array into multiple sub-arrays along the 3rd axis (depth).

Parameters:

ary : ndarray

An array, with at least 3 dimensions, to be divided into sub-arrays depth-wise, or along the third axis.

indices_or_sections: integer or 1D array :

If indices_or_sections is an integer, N, the array will be divided into N equal arrays along axis. If an equal split is not possible, a ValueError is raised.

if indices_or_sections is a 1D array of sorted integers representing indices along axis, the array will be divided such that each index marks the start of each sub-array. If an index exceeds the dimension of the array along axis, and empty sub-array is returned for that index.

axis : integer, optional

the axis along which to split. Default is 0.

Returns:

sub-arrays : list

A list of sub-arrays.

See also

array_split
Split an array into a list of multiple sub-arrays of near-equal size.
split
Split array into a list of multiple sub-arrays of equal size.
hsplit
Split array into a list of multiple sub-arrays horizontally
vsplit
Split array into a list of multiple sub-arrays vertically
concatenate
Join arrays together.
hstack
Stack arrays in sequence horizontally (column wise)
vstack
Stack arrays in sequence vertically (row wise)
dstack
Stack arrays in sequence depth wise (along third dimension)

Notes

dsplit requires that sub-arrays are of equal shape, whereas array_split allows for sub-arrays to have nearly-equal shape. Equivalent to split with axis = 2.

Examples

>>> x = np.arange(16.0).reshape(2, 2, 4)
>>> np.dsplit(x, 2)
<BLANKLINE>
[array([[[  0.,   1.],
        [  4.,   5.]],
<BLANKLINE>
       [[  8.,   9.],
        [ 12.,  13.]]]),
 array([[[  2.,   3.],
        [  6.,   7.]],
<BLANKLINE>
       [[ 10.,  11.],
        [ 14.,  15.]]])]
<BLANKLINE>
>>> x = np.arange(16.0).reshape(2, 2, 4)
>>> np.dsplit(x, array([3, 6]))
<BLANKLINE>
[array([[[  0.,   1.,   2.],
        [  4.,   5.,   6.]],
<BLANKLINE>
       [[  8.,   9.,  10.],
        [ 12.,  13.,  14.]]]),
 array([[[  3.],
        [  7.]],
<BLANKLINE>
       [[ 11.],
        [ 15.]]]),
 array([], dtype=float64)]

Previous topic

numpy.array_split

Next topic

numpy.hsplit

This Page

Quick search