Compute the Hamming distance between two integer-valued vectors. Notes ----- The Hamming distance between two vectors **x** and **y** is .. math:: d(\mathbf{x}, \mathbf{y}) = \\frac{1}{N} \sum_i \mathbb{1}_{x_i \\neq y_i} Parameters ---------- x,y : :py:c
(x, y)
| 107 | |
| 108 | |
| 109 | def hamming(x, y): |
| 110 | """ |
| 111 | Compute the Hamming distance between two integer-valued vectors. |
| 112 | |
| 113 | Notes |
| 114 | ----- |
| 115 | The Hamming distance between two vectors **x** and **y** is |
| 116 | |
| 117 | .. math:: |
| 118 | |
| 119 | d(\mathbf{x}, \mathbf{y}) = \\frac{1}{N} \sum_i \mathbb{1}_{x_i \\neq y_i} |
| 120 | |
| 121 | Parameters |
| 122 | ---------- |
| 123 | x,y : :py:class:`ndarray <numpy.ndarray>` s of shape `(N,)` |
| 124 | The two vectors to compute the distance between. Both vectors should be |
| 125 | integer-valued. |
| 126 | |
| 127 | Returns |
| 128 | ------- |
| 129 | d : float |
| 130 | The Hamming distance between **x** and **y**. |
| 131 | """ |
| 132 | return np.sum(x != y) / len(x) |