0
我希望生成固定大小n = 5
如何生成一個特定元素爲1,其餘爲0的列表?
條件m = 10
列表: 我有長度m
z = [0, 4, 3, 2, 4, 1, 3, 2, 1, 0]
上面列表包含應爲1的元素的指數列表z
。 該程序應該生成
[1,0,0,0,0] # element at index 0 is 1, rest are 0 as dictated by condition list z
[0,0,0,0,1] # element at index 4 is 1, rest are 0
[0,0,0,1,0] # element at index 3 is 1, rest are 0
[0,0,1,0,0] # element at index 2 is 1, rest are 0
.
.