Q:

matrix representation in python

columns = []
grid = []

num_of_rows = 3
num_of_columns = 4

#creates the matrix
for x in range(0, num_of_rows): # 3 rows by 4 columns
    for y in range(0, num_of_columns): 
        columns.append((x, y))
    grid.append(columns.copy())
    columns = []

#prints the grid in the matrix format
for x in range(0, len(grid)):
    print(grid[x])
    
#output:
# [(0, 0), (0, 1), (0, 2), (0, 3)]
# [(1, 0), (1, 1), (1, 2), (1, 3)]
# [(2, 0), (2, 1), (2, 2), (2, 3)]
1
// 3 x 4 matrix
     1 2 3 4
M =  4 5 6 7
     6 7 8 9

// 2 x 3 matrix in Python
A = ( [ 2, 5, 7 ],
      [ 4, 7, 9 ] )

// 3 x 4 matrix in Python where entries are floating numbers
B = ( [ 1.0, 3.5, 5.4, 7.9 ],
      [ 9.0, 2.5, 4.2, 3.6 ],
      [ 1.5, 3.2, 1.6, 6.5 ] )
0

New to Communities?

Join the community