EC Lecture Notes - Lecture 5: Main Diagonal, Numpy

6 views2 pages

Document Summary

An identity array is a square matrix with all the main diagonal elements as 1 and the rest as 0. The default type of elements is float. import numpy print numpy. identity(3) #3 is for dimension 3 x 3. The eye tool returns a 2-d array with 1"s as the diagonal and 0"s elsewhere. 0. ]] print numpy. eye(8, 7, k = -2) # 8 x 7 dimensional array with second lower diagonal 1. Your task is to print an array of size n*m with its main diagonal elements as 1"s and 0"s everywhere else. A single line containing the space separated values of n and m. # eye and identity in python - hacker rank solution. # eye and identity in python - hacker rank solution start import numpy numpy. set_printoptions(sign=" ") print(numpy. eye(*map(int, input(). split()))) # eye and identity in python - hacker rank solution end https://numpy. org/doc/stable/reference/generated/numpy. set_p rintoptions. html.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents