numpy.identity() in Python Last Updated : 22 Apr, 2025 Comments Improve Suggest changes Like Article Like Report numpy.identity() function is used to create an identity matrix which is used to make identity matrix. This is commonly used in linear algebra and numerical computations. It has the following properties:Diagonal elements are all 1s.Non-diagonal elements are all 0s.Syntax: numpy.identity(n, dtype=None)where:n : It takes int value and is Dimension n x n of output array dtype : It returns Data type of returned array. It is optional and by default it is float. In the below example we use numpy.identity() to create identity matrices of size 2x2 and 4x4 with 1s on the diagonal and 0s elsewhere. The dtype=float specifies that the matrix elements should be float type. Python import numpy as geek b = geek.identity(2, dtype = float) print("Matrix b : \n", b) a = geek.identity(4) print("\nMatrix a : \n", a) Output : Identity MatrixIt is useful for linear algebra operations like matrix multiplication, transformations and solving equations. Comment More infoAdvertise with us Next Article numpy.identity() in Python M Mohit Gupta_OMG Improve Article Tags : Misc Python Python-numpy Python numpy-arrayCreation Practice Tags : Miscpython Similar Reads numpy.i0() function | Python numpy.i0() function is the modified Bessel function of the first kind, order 0. it's usually denoted by I0. Syntax : numpy.i0(x) Parameters : x : [array_like, dtype float or complex] Argument of the Bessel function. Return : [ndarray, shape = x.shape, dtype = x.dtype] The modified Bessel function ev 1 min read numpy.nonzero() in Python numpy.nonzero()function is used to Compute the indices of the elements that are non-zero. It returns a tuple of arrays, one for each dimension of arr, containing the indices of the non-zero elements in that dimension. The corresponding non-zero values in the array can be obtained with arr[nonzero(ar 2 min read numpy.fromiter() function â Python NumPy's fromiter() function is a handy tool for creating a NumPy array from an iterable object. This iterable can be any Python object that provides elements one at a time. The function is especially useful when you need to convert data from a custom data source, like a file or generator, into a Num 2 min read numpy.who function - Python numpy.who() function print the NumPy arrays in the given dictionary. Syntax : numpy.who(vardict = None) Parameters : vardict : [dict, optional] A dictionary possibly containing ndarrays. Return : Returns âNoneâ. If there is no dictionary passed in or vardict is None then returns NumPy arrays in the 1 min read numpy matrix operations | identity() function numpy.matlib.identity() is another function for doing matrix operations in numpy. It returns a square identity matrix of given input size. Syntax : numpy.matlib.identity(n, dtype=None) Parameters : n : [int] Number of rows and columns in the output matrix. dtype : [optional] Desired output data-type 1 min read Python - tensorflow.identity_n() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. identity_n() is used get a list of Tensor with same shape and content as input Tensor. Syntax: tensorflow.identity_n( input, name) Parameters: input:  It is a Tensor.na 2 min read numpy.ndarray.fill() in Python numpy.ndarray.fill() method is used to fill the numpy array with a scalar value. If we have to initialize a numpy array with an identical value then we use numpy.ndarray.fill(). Suppose we have to create a NumPy array a of length n, each element of which is v. Then we use this function as a.fill(v). 2 min read bin() in Python Python bin() function returns the binary string of a given integer. bin() function is used to convert integer to binary string. In this article, we will learn more about Python bin() function. Example In this example, we are using the bin() function to convert integer to binary string. Python3 x = b 2 min read numpy.issubclass_() function â Python numpy.issubclass_() function is used to determine whether a class is a subclass of a second class. Syntax : numpy.issubclass_(arg1, arg2) Parameters : arg1 : [class] Input class. True is returned if arg1 is a subclass of arg2. arg2 : [class or tuple of classes] Input class. If a tuple of classes, Tr 1 min read numpy.fromstring() function â Python numpy.fromstring() function create a new one-dimensional array initialized from text data in a string. Syntax : numpy.fromstring(string, dtype = float, count = -1, sep = ' ') Parameters : string : [str] A string that contained the data. dtype : [data-type, optional] Data-type of the array. Default d 1 min read Like