Logo

Programming-Idioms

History of Idiom 26 > diff from v93 to v94

Edit summary for version 94 by ssss:
[Python] saas

Version 93

2021-12-19, 13:28:04

Version 94

2021-12-19, 13:28:29

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Variables
x,m,n
Variables
x,m,n
Extra Keywords
2d
Extra Keywords
2d
Code
x = [[0] * n for _ in range(m)]
Code
print(x, m, n)
Comments bubble
Do not just "multiply by m", which would duplicate the references to the inner arrays.
Comments bubble
Do not just "multiply by m", which would duplicate the references to the inner arrays.