Skip to content

komm.UnaryCode

Unary code. It is an integer code. For the definition of this code, see Wikipedia: Unary coding.

encode()

Encode the input integer array.

Parameters:

  • input (ArrayLike)

    The input integer array. It must be a one-dimensional array.

Returns:

  • output (NDArray[integer])

    The sequence of bits corresponding to the input integer array.

Examples:

>>> code = komm.UnaryCode()
>>> code.encode([4, 1, 3])
array([1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0])

decode()

Decode the input bit array.

Parameters:

  • input (ArrayLike)

    The input bit array. It must be a one-dimensional array.

Returns:

  • output (NDArray[integer])

    The sequence of integers corresponding to the input bit array.

Examples:

>>> code = komm.UnaryCode()
>>> code.decode([1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0])
array([4, 1, 3])