# coding=utf-8 # Author:Tommy_Zane # Time:2019/10/21 ''' 哈达玛矩阵的Python实现分享 ''' import numpy as np def Creat_Hadmard(i = 4, j = 4): '哈达玛矩阵的维数是2的幂次方,2^(a) 如(2,4,8,16...)' temp = i & j result = 0 for step in range(4): result += ((temp >> step) & 1) if 0 == result % 2: sign = 1 else: sign = -1 return sign if __name__ == '__main__': Row_Matrix = 4 Column_Matrix = 4 Hadmard = np.ones((Row_Matrix, Column_Matrix), dtype = np.float32) for i in range(Row_Matrix): for j in range(Column_Matrix): Hadmard[i][j] = Creat_Hadmard(i, j) print(Hadmard)
使用Python生成哈达玛矩阵
最新推荐文章于 2024-08-14 12:56:32 发布