如何创建大小为10的矩阵(数组)并将所有值设置为0冲突(i,j)=0

kg7wmglp  于 2021-09-08  发布在  Java
关注(0)|答案(2)|浏览(302)
N = 10

# input the number of columns

M = 10

# initializing the matrix

res = [ [ i*j for i in range(N) ] for j in range(M) ]
clash(i,j)=0

# printing in multiple lines

print("Multiline representation")
for i in range(N):
   for j in range(M):
          #matrix.append(["0"]*100)
      print(res[i][j] ,end =" ")
   print("")

存在一个错误,显示无法在clash(i,j)=0时分配到函数调用。因此,我真的需要帮助!

wh6knrhe

wh6knrhe1#

也许通过创建列表? matrix = [[0] * 10] * 10 形象

1u4esq0p

1u4esq0p2#

我相信numpy更适合这样做

import numpy as np

array = np.zeros((i,j))

编辑:要设置值,请使用:

array[y][x] = value

相关问题