def hadamard(n, dtype=int):
<EOL>if n < <NUM_LIT:1>:<EOL><INDENT>lg2 = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>lg2 = int(math.log(n, <NUM_LIT:2>))<EOL><DEDENT>if <NUM_LIT:2> ** lg2 != n:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>H = np.array([[<NUM_LIT:1>]], dtype=dtype)<EOL>for i in range(<NUM_LIT:0>, lg2):<EOL><INDENT>H = np.vstack((np.hstack((H, H)), np.hstack((H, -H))))<EOL><DEDENT>return H<EOL>
Construct a Hadamard matrix.

Constructs an n-by-n Hadamard matrix, using Sylvester's
construction.  `n` must be a power of 2.

Parameters
----------
n : int
    The order of the matrix.  `n` must be a power of 2.
dtype : numpy dtype
    The data type of the array to be constructed.

Returns
-------
H : (n, n) ndarray
    The Hadamard matrix.

Notes
-----
.. versionadded:: 0.8.0

Examples
--------
>>> from scipy.linalg import hadamard
>>> hadamard(2, dtype=complex)
array([[ 1.+0.j,  1.+0.j],
       [ 1.+0.j, -1.-0.j]])
>>> hadamard(4)
array([[ 1,  1,  1,  1],
       [ 1, -1,  1, -1],
       [ 1,  1, -1, -1],
       [ 1, -1, -1,  1]])