numpy_vector_zone_translation#

caf.toolkit.translation.numpy_vector_zone_translation(vector, translation, translation_dtype=None, check_shapes=True, check_totals=True)[source]#

Efficiently translates a vector between index systems.

Uses the given translation matrix to translate a vector of values from one index system to another. This has been written in pure numpy operations. This algorithm optimises for speed by expanding the translation across 2 dimensions. For large vectors this can result in MemoryError. If this happens, the translation_dtype needs to be set to a smaller data type, sacrificing accuracy.

Parameters:
  • vector (ndarray) – The vector to translate. Must be one dimensional. e.g. (n_in, )

  • translation (ndarray) – The matrix defining the weights to use to translate matrix. Should be of shape (n_in, n_out), where the output vector shape will be (n_out, ). A value of 0.5 in translation[0, 2] Would mean that 50% of the value in index 0 of vector should end up in index 2 of the output.

  • translation_dtype (dtype | None) – The numpy datatype to use to do the translation. If None, then the dtype of the vector is used. Where such high precision isn’t needed, a more memory and time efficient data type can be used.

  • check_shapes (bool) – Whether to check that the input and translation shapes look correct. Optionally set to False if checks have been done externally to speed up runtime.

  • check_totals (bool) – Whether to check that the input and output vectors sum to the same total.

Returns:

vector, translated into (n_out, ) shape via translation.

Return type:

translated_vector

Raises:

ValueError: – Will raise an error if vector is not a 1d array, or if translation does not have the same number of rows as vector.