Eye and Identity HackerRank Solution

This Python program is about creating an identity matrix using the numpy library. An identity matrix is a square matrix in which all the elements of the principal diagonal are ones and all other elements are zeros. The user provides two integers as input, which represent the dimensions of the matrix.

Secure your next interview 🎯

CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷

Here is the Eye and Identity HackerRank Solution HackerRank solution using CodeRankGPT:

The solution works by using the numpy library's 'eye' function, which returns a 2-D array with ones on the diagonal and zeros elsewhere. The dimensions of the matrix are determined by the two integers provided by the user. The 'set_printoptions' function is used to set the legacy parameter to '1.13' to ensure the output format matches the problem's requirements.


import numpy as np

np.set_printoptions(legacy="1.13")
n, m = map(int, input().split())
print(np.eye(n, m, k=0))

If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.

AI is here now, and other candidates might be using it to get ahead and win the job. 🧐

Built on Unicorn Platform