counts = [[2, 2, 2, 0], [2, 2, 1, 0]]
countsminusone = [[1, 1, 1, -1], [1, 1, 0, -1]] #Which is counts - 1
对于每一个值,其中countsminusone为0或小于0,我想用1
countsminusone1 = [[1 if x == 0 or x < 0 else x for x in pair] for pair in countsminusone] #I cannot get this to work
来代替它,然后通过countsminusone划分数
Divide = [[n/d for n, d in zip(subq, subr)] for subq, subr in zip(counts, countsminusone)] #This should work if the above works
'x == 0或x <0' =='x <1'为整数... – brianpck
或者至少x <= 0 ... –
是什么让你觉得它不起作用?请提供真实和预期的结果。 –