src.helpers.general.numpy_indexing module

This module contains general helper functions.

It includes the following methods: - slices_to_index_array: convert multiple slices to an index array for vectorized integer indexing - string_to_index: convert a string of indexing information to an actual indexing object

Contact person: Stefan Riedmaier Creation date: 29.06.2020 Python version: 3.8

src.helpers.general.numpy_indexing.slices_to_index_array(start_idx, end_idx=(), length=array([], dtype=float64), axis=-1, x=array([], dtype=float64), values=0, repeats=True)

This function converts multiple slices to an index array for vectorized integer indexing at once.

Parameters:
  • start_idx (tuple) – start indices

  • end_idx (tuple) – (alternative to length) end indices

  • length (np.ndarray) – (alternative to end_idx) length of the slices

  • axis (int) – (optional) axis parameter to select one dimension from the index tuples for slicing

  • x (np.ndarray) – (optional) array in which the values shall be inserted between the slice indices

  • values (np.array) – (optional) values to be inserted between the slice indices

  • repeats (bool) – (optional) flag whether the indices and values must be repeated times the “length”

Returns:

integer index array, array filled with values

Return type:

(tuple, np.ndarray)

src.helpers.general.numpy_indexing.string_to_index(s)

This function converts a string of indexing information to an actual indexing object.

It is intended for config parsing where the user enters the indexing information in a string field.

Parameters:

s (string) – indexing information

Returns:

index object

Return type:

int | slice | list