module documentation
Helper functions for slice operations on numpy arrays
Function | around |
returns a slice of a in the shape of b about the centre of a Accepts np.ndarray or tuple for each argument |
Function | from |
Build a tuple of slices from a string representation |
Function | get |
Returns the indices of an array slice. Indicies will select the sliced part of an array. |
Function | iter |
Iterator that returns the sliced indices of a sliced array. |
Function | iter |
Iterator that returns the sliced indices of a sliced array, and slices that select only grouped axes |
Function | squeeze |
Given a tuple of slices (slice_tuple ), if a slice only selects a single index, replace it with an index instead. e.g., [10:100, 13:14, 50:60] -> [10:100, 13, 50:60] |
Function | unsqueeze |
Given a tuple of slices and indices (slice_tuple ), replace all indices with a slice from i->i+1 e.g., [10:100, 13, 50:60] -> [10:100, 13:14, 50:60] |
Variable | _lgr |
Undocumented |
returns a slice of a in the shape of b about the centre of a Accepts np.ndarray or tuple for each argument
def get_indices(a:
np.ndarray
, slice_tuple: tuple[ slice | int, ...] | np.ndarray[ int] | None
, as_tuple: bool
= True) -> np.ndarray | tuple[ np.ndarray, ...]
:
¶
Returns the indices of an array slice. Indicies will select the sliced part of an array.
- a
- The array to get the indicies of a slice of
- slice_tuple
- A tuple of length
a.ndim
that specifies the slices - as_tuple
- If True will return an
a.ndim
length tuple, otherwise will return a numpy array.
def iter_indices(a:
np.ndarray
, slice_tuple: tuple[ slice | int, ...] | np.ndarray[ int] | None
= None, group: tuple[ int, ...]
= tuple(), squeeze=True) -> Iterator[ tuple[ np.ndarray]]
:
¶
Iterator that returns the sliced indices of a sliced array.
- a
- The array to get the indicies of a slice of
- slice_tuple
- A tuple of length
a.ndim
that specifies the slices - group
- Axes that are not iterated over (i.e., they are grouped together). E.g.
if a.shape=(3,5,7,9) and group=(1,3), then on iteration the indices
idx
select a slice froma
such that a[idx].shape=(5,9). - squeeze
- Should non-grouped axes be merged (need one for loop for all of them), or should they remain separate (need a.ndim - len(group) loops).
def iter_indices_with_slices(a:
np.ndarray
, slice_tuple: tuple[ slice | int, ...] | np.ndarray[ int] | None
= None, group: tuple[ int, ...]
= tuple(), squeeze=True) -> Iterator[ tuple[ np.ndarray]]
:
¶
Iterator that returns the sliced indices of a sliced array, and slices that select only grouped axes
- a
- The array to get the indicies of a slice of
- slice_tuple
- A tuple of length
a.ndim
that specifies the slices - group
- Axes that are not iterated over (i.e., they are grouped together). E.g.
if a.shape=(3,5,7,9) and group=(1,3), then on iteration the indices
idx
select a slice froma
such that a[idx].shape=(5,9). - squeeze
- Should non-grouped axes be merged (need one for loop for all of them), or should they remain separate (need a.ndim - len(group) loops).
Given a tuple of slices (slice_tuple
), if a slice only selects a single index, replace it with an index instead.
e.g., [10:100, 13:14, 50:60] -> [10:100, 13, 50:60]