I'm trying to create an identity matrix that accepts input and returns an identity matrix(list or lists) of size by size, with only 1's and 0's without using numpy.
So if the user inputs: >>>matrix(4)
, the output should be: [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
So far I've setup my list comprehension like this:matrix = [[0 for _ in range(3)] for _ in range(3)]
Any suggestions on how to setup my comprehension would be appreciated.
question from:
https://stackoverflow.com/questions/65922346/python-size-by-size-matrix-that-allows-input-and-returns-list-of-lists-elements 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…