为什么赋值运算符会影响所有元素?

时间:2019-10-02 21:07:58

标签: python python-3.x numpy numpy-ndarray

waiting = [[0]]* 5 # we can assume the waiting to contain 5 lists
print((np.shape(waiting))) # (5, 1)
waiting[0][0] = waiting[0][0] + (0.72) # only the value at the first list should get changed
print(waiting) # [[0.72], [0.72], [0.72], [0.72], [0.72]] when I expected only the first list's 0 
                # to become 0.72

如评论中所述,为什么所有数组都受到第三行waiting[0][0] = waiting[0][0] + (0.72)

的影响

0 个答案:

没有答案