matrix.matrix_equalization

Functions

array_equalization(→ int)

This algorithm equalizes all elements of the input vector

Module Contents

matrix.matrix_equalization.array_equalization(vector: list[int], step_size: int) int

This algorithm equalizes all elements of the input vector to a common value, by making the minimal number of “updates” under the constraint of a step size (step_size).

>>> array_equalization([1, 1, 6, 2, 4, 6, 5, 1, 7, 2, 2, 1, 7, 2, 2], 4)
4
>>> array_equalization([22, 81, 88, 71, 22, 81, 632, 81, 81, 22, 92], 2)
5
>>> array_equalization([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 5)
0
>>> array_equalization([22, 22, 22, 33, 33, 33], 2)
2
>>> array_equalization([1, 2, 3], 0)
Traceback (most recent call last):
ValueError: Step size must be positive and non-zero.
>>> array_equalization([1, 2, 3], -1)
Traceback (most recent call last):
ValueError: Step size must be positive and non-zero.
>>> array_equalization([1, 2, 3], 0.5)
Traceback (most recent call last):
ValueError: Step size must be an integer.
>>> array_equalization([1, 2, 3], maxsize)
1