“Python 2D -Matrix deklarieren” Code-Antworten

Erstellen Sie ein 2D -Array in 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

2D -Array in 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 deklarieren

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

Ähnliche Antworten wie “Python 2D -Matrix deklarieren”

Fragen ähnlich wie “Python 2D -Matrix deklarieren”

Weitere verwandte Antworten zu “Python 2D -Matrix deklarieren” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen