<jupyter_start><jupyter_text>Function hadamardmatrix  SynopseKernel matrix for the Hadamard Transform.   - **A = hadamardmatrix(N)**       - Output:           - **A**: Image.       - Input:           - **N**: Double.  Function code<jupyter_code>import numpy as np
 
def hadamardmatrix(N):
 
    def bitsum(x):
        s = 0 * x
        while x.any():
            s += x & 1
            x >>= 1
        return s
 
    n = np.floor(np.log(N)/np.log(2))
 
    if 2**n != N:
        raise Exception('error: size {0} is not multiple of power of 2'.format(N))
 
    u, x = np.meshgrid(range(N), range(N))
 
    A = ((-1)**(bitsum(x & u)))/np.sqrt(N)
    return A
testing = (__name__ == "__main__")

if testing:
    ! jupyter nbconvert --to python hadamardmatrix.ipynb
    import numpy as np
    import sys,os
    import matplotlib.image as mpimg
    ea979path = os.path.abspath('../../')
    if ea979path not in sys.path:
        sys.path.append(ea979path)
    import ea979.src as ia<jupyter_output>[NbConvertApp] Converting notebook hadamardmatrix.ipynb to python
[NbConvertApp] Writing 1445 bytes to hadamardmatrix.py<jupyter_text>Examples Example 1<jupyter_code>if testing:
    A = ia.hadamardmatrix(128)
    ia.adshow(ia.normalize(A, [0, 255]))<jupyter_output><empty_output><jupyter_text>Example 2<jupyter_code>if testing:
    A = ia.hadamardmatrix(4)
    print(A)
    print(np.dot(A, np.transpose(A)))<jupyter_output>[[ 0.5  0.5  0.5  0.5]
 [ 0.5 -0.5  0.5 -0.5]
 [ 0.5  0.5 -0.5 -0.5]
 [ 0.5 -0.5 -0.5  0.5]]
[[ 1.  0.  0.  0.]
 [ 0.  1.  0.  0.]
 [ 0.  0.  1.  0.]
 [ 0.  0.  0.  1.]]<jupyter_text>Measuring time:<jupyter_code>if testing:
    print('Computational time is:')
    %timeit ia.hadamardmatrix(128)<jupyter_output>Computational time is:
1000 loops, best of 3: 802 µs per loop
{'fraction_non_alphanumeric': 0.1505316172355904, 'fraction_numerical': 0.05204252937884723, 'mean_word_length': 2.597585513078471, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '261627', 'license': 'MIT', 'n_tokens_mistral': 774, 'n_tokens_neox': 718, 'n_words': 170, 'path': 'src/hadamardmatrix.ipynb', 'repo_name': 'lrittner/ia979', 'size': '1787'}