def encode(B):
    """ Encode data using Hamming(7, 4) code.

    E.g.:
        encode([0, 0, 1, 1])

        encode([[0, 0, 0, 1],
                [0, 1, 0, 1]])

    :param array B: binary data to encode (must be shaped as (4, ) or (-1, 4)).

    """
    B = array(B)

    flatten = False
    if len(B.shape) == 1:
        flatten = True
        B = B.reshape(1, -1)

    if B.shape[1] != data_size:
        raise ValueError('Data must be shaped as (4, ) or (-1, 4)')

    C = dot(G, B.T).T % 2

    if flatten:
        C = C.flatten()

    return C
def encode ( B ) : B = array ( B ) flatten = False if len ( B . shape ) == 1 : flatten = True B = B . reshape ( 1 , - 1 ) if B . shape [ 1 ] != data_size : raise ValueError ( 'Data must be shaped as (4, ) or (-1, 4)' ) C = dot ( G , B . T ) . T % 2 if flatten : C = C . flatten ( ) return C
Encode data using Hamming(7, 4) code.

    E.g.:
        encode([0, 0, 1, 1])

        encode([[0, 0, 0, 1],
                [0, 1, 0, 1]])

    :param array B: binary data to encode (must be shaped as (4, ) or (-1, 4)).