jax.scipy.linalg.hadamard

Contents

jax.scipy.linalg.hadamard#

jax.scipy.linalg.hadamard(n, dtype=<class 'int'>)[source]#

Construct an n-by-n Hadamard matrix.

JAX implementation of scipy.linalg.hadamard().

For n a positive power of 2, the Hadamard matrix \(H_n\) satisfies \(H_n H_n^T = n I\). It is defined recursively by the Sylvester construction: \(H_1 = [[1]]\), and \(H_{2m} = \begin{bmatrix} H_m & H_m \\ H_m & -H_m \end{bmatrix}\).

Parameters:
  • n (int) – size of the matrix. Must be a positive power of 2.

  • dtype (DTypeLike) – output dtype. Defaults to int.

Returns:

A Hadamard matrix of shape (n, n).

Return type:

Array

Examples

>>> jax.scipy.linalg.hadamard(4)
Array([[ 1,  1,  1,  1],
       [ 1, -1,  1, -1],
       [ 1,  1, -1, -1],
       [ 1, -1, -1,  1]], dtype=int32)