0
Explain this code please !
import numpy print(numpy.eye(*map(int, input().split())))
2 Réponses
+ 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
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()