MCPcopy
hub / github.com/numpy/numpy / identity

Function identity

numpy/matlib.py:155–189  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

153 return a
154
155def 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
191def eye(n, M=None, k=0, dtype=float, order='C'):
192 """

Callers

nothing calls this directly

Calls 2

emptyFunction · 0.85
arrayFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…