Most of us, are aware of creating identity matrices using NumPy’s identity function but I’m restricted to use it in my assignment. I have to create an identity matrix without using the identity function of NumPy. Although, I have coded this by using the identity function too. Can someone help me in achieving the same goal but with some other NumPy functions?

The above code creates a 3x3 identity matrix with the help of the NumPy identity function.

Yes @safa same goal can be achieve by using array() function. Array function is a fundamental method that is used to create a new NumPy array object. It required one argument n , which can be a list, tuple, or other iterable containing the values to be stored in the array. The reshape() function is used to change the shape of an existing array without changing its values. The function takes two required argument n , one is the input array, and other is the new shape of the arrays.

For example, the following code creates a 1-dimensional array with identity values and reshape it in 3x3 matrix.