编程语言
首页 > 编程语言> > Python 求汉明码的最小距离

Python 求汉明码的最小距离

作者:互联网

#求汉明最小距离
def hm_code_length(hm_code):
    '''
    array()列表--数组
    mat() 列表--矩阵
    tolist() 矩阵--列表
    '''
    # 列表a用来装汉明码距离
    a = []
    for i in range(len(hm_code)):
        matV = np.mat(hm_code)
        # nonzero()将布尔数组转换成一组整数数组,然后使用整数数组进行下标运算。
        for j in range(i+1,len(hm_code)):
            if i < len(hm_code)-1:
                smstr = np.nonzero(matV[i] - matV[i+1])
                a.append(np.shape(smstr[1])[0])
    print a
    return min(a)

if __name__ == '__main__':
    random_sources()
    # (7,4)汉明码
    hanming_code = [[1, 0, 0, 0, 0, 1, 1], [0, 1, 0, 0, 1, 0, 1], [0, 0, 1, 0, 1, 1, 0], [0, 0, 0, 1, 1, 1, 1]]
    # print hanming_code
    print hm_code_length(hanming_code)

标签:__,matV,code,Python,hanming,最小,hm,np,汉明码
来源: https://blog.csdn.net/weixin_41931602/article/details/88374688