Answers for "how to initialise 2d matrix python"

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
0

python intitialize a 2d matrix

# initialize a matrix of rowxcol with -1
dp = [[-1]*col for _ in range(row)]
Posted by: Guest on May-26-2021

Python Answers by Framework

Browse Popular Code Answers by Language