RectPartition.index¶
- RectPartition.index(value, floating=False)[source]¶
Return the index of a value in the domain.
- Parameters:
- value
self.setelement Point whose index to find.
- floatingbool, optional
If True, then the index should also give the position inside the voxel. This is given by returning the integer valued index of the voxel plus the distance from the left cell boundary as a fraction of the full cell size.
- value
- Returns:
- indexint, float, tuple of int or tuple of float
Index of the value, as counted from the left. If
self.ndim > 1the result is a tuple, else a scalar. Iffloating=Truethe scalar is a float, else an int.
Examples
Get the indices of start and end:
>>> p = odl.uniform_partition(0, 2, 5) >>> p.index(0) 0 >>> p.index(2) 4
For points inside voxels, the index of the containing cell is returned:
>>> p.index(0.2) 0
By using the
floatingargument, partial positions inside the voxels can instead be determined:>>> p.index(0.2, floating=True) 0.5
These indices work with indexing, extracting the voxel in which the point lies:
>>> p[p.index(0.1)] uniform_partition(0.0, 0.4, 1)
The same principle also works in higher dimensions:
>>> p = uniform_partition([0, -1], [1, 2], (4, 1)) >>> p.index([0.5, 2]) (2, 0) >>> p[p.index([0.5, 2])] uniform_partition([ 0.5, -1. ], [ 0.75, 2. ], (1, 1))