Explain this code please ! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Explain this code please !

import numpy print(numpy.eye(*map(int, input().split())))

28th Dec 2021, 5:58 PM
Stevewa
Stevewa - avatar
2 Answers
+ 4
Copy the code and run it on sololearn playground – this way you can see what happens and experiment with it. map() simply casts all input to integer. Read the documentation to find out about numpy.eye: https://numpy.org/doc/stable/reference/generated/numpy.eye.html
28th Dec 2021, 6:22 PM
Lisa
Lisa - avatar
0
Input: 3 4 2 numpy.eye(*map(int, input().split())) => numpy.eye(*map(int, ["3", "4", " 2"])) => numpy.eye(*[3, 4, 2]) => numpy.eye(3, 4, 2) print(numpy.eye(3, 4, 2)) Output: [[0., 0., 1., 0.], [0., 0., 0., 1.], [0., 0., 0., 0.]] Just post if you need explanation if you didn't understood the role of numpy.eye()
28th Dec 2021, 8:15 PM
VCoder
VCoder - avatar