Answers for "python initialize 2d array of size n"

3

python initialize a 2d array

x = [[foo for i in range(10)] for j in range(10)]
# x is now a 10x10 array of 'foo' (which can depend on i and j if you want)
Posted by: Guest on November-09-2020
1

python create n*n matrix

# Creates a list containing 5 lists, each of 8 items, all set to 0
w, h = 8, 5;
Matrix = [[0 for x in range(w)] for y in range(h)]
Posted by: Guest on September-28-2020
0

python initialize a 2d array

bar = [SOME EXPRESSION for item in some_iterable]
Posted by: Guest on November-09-2020

Code answers related to "python initialize 2d array of size n"

Python Answers by Framework

Browse Popular Code Answers by Language