# convert.py -- converts the files of McKay's catalogue of Hadamard matrices, to be downloaded from # https://users.cecs.anu.edu.au/~bdm/data/hadamard.html and saved as mckay/had16.txt and mckay/had20.txt, into # text files of +-1 entries. In these files each line is a matrix, each row being a hexadecimal number, whose binary # digits give the row, with 1 -> +1 and 0 -> -1. We check H H^t = N and write matrices/hadN_k.txt, for k = 0, 1, ... # in the order of the file. Usage: python3 convert.py mckay/had16.txt 16 import numpy as np, sys, os src,N=sys.argv[1],int(sys.argv[2]) os.makedirs('matrices',exist_ok=True) lines=[l.split() for l in open(src) if l.strip()] for k,l in enumerate(lines): assert len(l)==N H=np.array([[1 if (int(h,16)>>(N-1-j))&1 else -1 for j in range(N)] for h in l],dtype=int) assert np.array_equal(H@H.T,N*np.eye(N,dtype=int)) np.savetxt(f'matrices/had{N}_{k}.txt',H,fmt='%d') print(len(lines),'Hadamard matrices of order',N,'converted and checked')