将元组插入2D数组

时间:2017-05-13 00:38:57

标签: python python-2.7 multidimensional-array tuples

我试图将一些元组插入到2D数组中,但由于某种原因,x值似乎没有增加。

x_axis = 20
y_axis = 4
arr = [[None]*y_axis]*x_axis
for x in range(x_axis):
    for y in range(y_axis):
        arr[x][y] = (x,9,y,6)

for x in range(x_axis):
    for y in range(y_axis):
        print arr[x][y]

我得到了这个:

(19, 9, 0, 6)
(19, 9, 1, 6)
(19, 9, 2, 6)
(19, 9, 3, 6)
(19, 9, 0, 6)
(19, 9, 1, 6)
(19, 9, 2, 6)
(19, 9, 3, 6)
(19, 9, 0, 6)
(19, 9, 1, 6)
(19, 9, 2, 6)
(19, 9, 3, 6)
(19, 9, 0, 6)
(19, 9, 1, 6)
(19, 9, 2, 6)
(19, 9, 3, 6)
(19, 9, 0, 6)
(19, 9, 1, 6)
(19, 9, 2, 6)
(19, 9, 3, 6)

我不知道x为什么坚持19(范围的最后一个数字)而不仅仅是0-19(包括0-19)。

0 个答案:

没有答案