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

Function identity

numpy/_core/numeric.py:2179–2215  ·  view source on GitHub ↗

Return the identity array. The identity array is a square array with ones on the main diagonal. Parameters ---------- n : int Number of rows (and columns) in `n` x `n` output. dtype : data-type, optional Data-type of the output. Defaults to ``float``.

(n, dtype=None, *, like=None)

Source from the content-addressed store, hash-verified

2177@finalize_array_function_like
2178@set_module('numpy')
2179def identity(n, dtype=None, *, like=None):
2180 """
2181 Return the identity array.
2182
2183 The identity array is a square array with ones on
2184 the main diagonal.
2185
2186 Parameters
2187 ----------
2188 n : int
2189 Number of rows (and columns) in `n` x `n` output.
2190 dtype : data-type, optional
2191 Data-type of the output. Defaults to ``float``.
2192 ${ARRAY_FUNCTION_LIKE}
2193
2194 .. versionadded:: 1.20.0
2195
2196 Returns
2197 -------
2198 out : ndarray
2199 `n` x `n` array with its main diagonal set to one,
2200 and all other elements 0.
2201
2202 Examples
2203 --------
2204 >>> import numpy as np
2205 >>> np.identity(3)
2206 array([[1., 0., 0.],
2207 [0., 1., 0.],
2208 [0., 0., 1.]])
2209
2210 """
2211 if like is not None:
2212 return _identity_with_like(like, n, dtype=dtype)
2213
2214 from numpy import eye
2215 return eye(n, dtype=dtype, like=like)
2216
2217
2218_identity_with_like = array_function_dispatch()(identity)

Callers 3

test_identityMethod · 0.90

Calls 1

eyeFunction · 0.90

Tested by 3

test_identityMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…