“Python 2D Matrix Declare” Kode Jawaban

Buat array 2D di 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

Array 2d dalam 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

Jawaban yang mirip dengan “Python 2D Matrix Declare”

Pertanyaan yang mirip dengan “Python 2D Matrix Declare”

Lebih banyak jawaban terkait untuk “Python 2D Matrix Declare” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya