m = [[3.5, 1.0, 9.2, 4.0], [0, 0, 0, 0], [3.0, 1.0, 8.0, -2.0]] c_idx = 2 for count 4 in category 4: for count5 for category (lane (count4)): if m [count4] Index (M [count4] [Count5]) == c_idx: M [count4] = m [count4] [: c_idx] + [0] + m [count4] [c_idx + 1:] count4 + = 1 count5 + = 1 Print (m)
So I want to rewrite the element of a certain position for the list, M but it shows me an error:
If M [count4] Index (M [count4] [count5]) == c_idx: index error: out of range index index
The result should be:
[ [3.5, 1.0, 0, 4.0], [0, 0, 0, 0], [3.0, 1.0, 0, -2.0]]
I do not know where I was wrong I'll help people!
just type count4 + = 1
and
m = [[3.5, 1.0, 9.2, 4.0], [0, 0, 0, 0] 2.0]] for c_idx = 2 limit (in the count4): in the count5 for the category (lane (count4)): If M [count4]. Index (M [count4] [count5]) == c_idx: m [count4] = m [count4] [: c_idx] + [0] + m [count4] [c_idx + 1:] print (m) [[3.5, 1.0, 0, 4.0], [0, 0, 0, 0], [3.0, 1.0, 0, -2.0]]
for / loop
Category
Already + = 1
For you however, there are many cleaner outlines mentioned in the other answer.
Comments
Post a Comment