Logo

Programming-Idioms

History of Idiom 26 > diff from v84 to v85

Edit summary for version 85 by programming-idioms.org:
Admin deletes impl 4915: Dupe of impl #3826

Version 84

2021-08-16, 19:55:33

Version 85

2021-08-16, 19:56:16

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)]
Comments bubble
You can't use the multiplication idiom for the outer array, because, it would just duplicate the references to the inner arrays.