def syndrome(msg):
""" passed a list of hamming(8,4)-encoded bits (integers, 1 or 0),
returns an error syndrome for that list """
msg = np.reshape(np.array(msg), (-1, 8)).T
# syndrome generation matrix
transition = np.mat('0,1,1,1,1,0,0,0;\
1,0,1,1,0,1,0,0;\
1,1,0,1,0,0,1,0;\
1,1,1,0,0,0,0,1')
result = np.dot(transition, msg)
# mod 2 the matrix multiplication
return np.mod(result, 2)
评论列表
文章目录