RectPartition.__getitem__

RectPartition.__getitem__(self, indices)[source]

Return self[indices].

Parameters
indicesindex expression

Object determining which parts of the partition to extract. None (new axis) and empty axes are not supported.

Examples

Take every second grid point. Note that is is in general non-uniform:

>>> partition = odl.uniform_partition(0, 10, 10)
>>> partition[::2]
nonuniform_partition(
    [ 0.5,  2.5,  4.5,  6.5,  8.5],
    min_pt=0.0, max_pt=10.0
)

A more advanced example is:

>>> intvp = odl.IntervalProd([-1, 1, 4, 2], [3, 6, 5, 7])
>>> grid = odl.RectGrid([-1, 0, 3], [2, 4], [5], [2, 4, 7])
>>> part = odl.RectPartition(intvp, grid)
>>> part
nonuniform_partition(
    [-1.,  0.,  3.],
    [ 2.,  4.],
    [ 5.],
    [ 2.,  4.,  7.],
    min_pt=[-1.,  1.,  4.,  2.], max_pt=[ 3.,  6.,  5.,  7.]
)

Take an advanced slice (every second along the first axis, the last in the last axis and everything in between):

>>> part[::2, ..., -1]
nonuniform_partition(
    [-1.,  3.],
    [ 2.,  4.],
    [ 5.],
    [ 7.],
    min_pt=[-1. ,  1. ,  4. ,  5.5], max_pt=[ 3.,  6.,  5.,  7.]
)

Too few indices are filled up with an ellipsis from the right:

>>> part[1]
nonuniform_partition(
    [ 0.],
    [ 2.,  4.],
    [ 5.],
    [ 2.,  4.,  7.],
    min_pt=[-0.5,  1. ,  4. ,  2. ], max_pt=[ 1.5,  6. ,  5. ,  7. ]
)

Colons etc work as expected:

>>> part[:] == part
True
>>> part[:, :, :] == part
True
>>> part[...] == part
True