Questions

How to use matrix in python?

0

I want to use a matrix in python like that of C/C++.

matrix = [][]

How to do that.



asked 1 year, 11 months ago
Reputation: 1





1 Answer

0

We can use matrix in python like,

Initializing

matrix = [ [0 for x in range(columns)] for y in range(rows) ]

It will initialize the matrix of dimension rows*columns with value 0.

Assigning

a number

matrix[2][3] = 23

or a character

matrix[2][3] = 'R'

Printing

a single element

print(matrix[2][3])

or complete matrix

print(matrix)

answered 1 year, 11 months ago
Reputation: 1





Your Answer

Nothing to preview

Post Answer



Asked:  1 year, 11 months ago
Viewed:  419 times
Active:  1 year, 11 months ago