decode_ternary_array

keras_mml.utils.array.encoding.decode_ternary_array(shape, encoded)[source]

Decodes the ternary array generated by encode_ternary_array().

Parameters:
  • shape (Tuple[int, ...]) – Shape of the original array.

  • encoded (bytes) – Encoded ternary array.

Raises:

ValueError – If the encoded byte string is empty.

Returns:

ndarray – The decoded ternary array.

Examples

>>> decode_ternary_array((6,), b"\xb4\xe0")
array([ 1, -1,  1,  0, -1,  1])
>>> decode_ternary_array((2, 3), b"n\x80")
array([[ 0,  1, -1],
       [-1,  0,  0]])
>>> decode_ternary_array((2, 2, 3), b"K\xe48")
array([[[ 0,  1, -1],
        [-1,  1,  0]],

       [[ 1,  0,  0],
        [ 0, -1,  1]]])
>>> decode_ternary_array((2, 2, 3), b"K\xe5\x9c")
array([[[ 0,  1, -1],
        [-1,  1,  0]],

       [[ 1, -1,  0],
        [ 0, -1,  1]]])