Returns the square identity matrix of given size. Parameters ---------- n : int Size of the returned identity matrix. dtype : data-type, optional Data-type of the output. Defaults to ``float``. Returns ------- out : matrix `n` x `n` matrix w
(n, dtype=None)
| 153 | return a |
| 154 | |
| 155 | def identity(n, dtype=None): |
| 156 | """ |
| 157 | Returns the square identity matrix of given size. |
| 158 | |
| 159 | Parameters |
| 160 | ---------- |
| 161 | n : int |
| 162 | Size of the returned identity matrix. |
| 163 | dtype : data-type, optional |
| 164 | Data-type of the output. Defaults to ``float``. |
| 165 | |
| 166 | Returns |
| 167 | ------- |
| 168 | out : matrix |
| 169 | `n` x `n` matrix with its main diagonal set to one, |
| 170 | and all other elements zero. |
| 171 | |
| 172 | See Also |
| 173 | -------- |
| 174 | numpy.identity : Equivalent array function. |
| 175 | matlib.eye : More general matrix identity function. |
| 176 | |
| 177 | Examples |
| 178 | -------- |
| 179 | >>> import numpy.matlib |
| 180 | >>> np.matlib.identity(3, dtype=np.int_) |
| 181 | matrix([[1, 0, 0], |
| 182 | [0, 1, 0], |
| 183 | [0, 0, 1]]) |
| 184 | |
| 185 | """ |
| 186 | a = array([1] + n * [0], dtype=dtype) |
| 187 | b = empty((n, n), dtype=dtype) |
| 188 | b.flat = a |
| 189 | return b |
| 190 | |
| 191 | def eye(n, M=None, k=0, dtype=float, order='C'): |
| 192 | """ |