Initialize empty matrix in Python

前端 未结 7 1271
旧巷少年郎
旧巷少年郎 2020-12-31 07:56

I am trying to convert a MATLAB code in Python. I don\'t know how to initialize empty matrix in Python.

MATLAB Code:

demod4(1) = [];
<
7条回答
  •  借酒劲吻你
    2020-12-31 08:32

    M=[]
    n=int(input())
    m=int(input())
    for j in range(n):
       l=[]
       for k in range(m):
           l.append(0)
       M.append(l)
    print(M)
    

    This is the traditional way of doing it matrix[m,n], However, python offers many cool ways of doing so as mentioned in other answers.

提交回复
热议问题