“Python 2D Matrix Declare” Réponses codées

Créez un tableau 2D en Python

def build_matrix(rows, cols):
    matrix = []

    for r in range(0, rows):
        matrix.append([0 for c in range(0, cols)])

    return matrix

if __name__ == '__main__':
    build_matrix(6, 10)
McBurd

Tableau 2D en python

from array import *

T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
for r in T:
    for c in r:
        print(c,end = " ")
    print()
Defiant Duck

Python 2D Matrix Declare

length, breadth = x, y
matrix = [[-1 for j in range(breadth)] for i in range(length)]
# every element is -1
Famous Finch

Réponses similaires à “Python 2D Matrix Declare”

Questions similaires à “Python 2D Matrix Declare”

Plus de réponses similaires à “Python 2D Matrix Declare” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code