Peter
0
Q:

initialise a 2d array python

# Using above first method to create a  
# 2D array 
rows, cols = (5, 5) 
arr = [[0]*cols]*rows 
print(arr) 
4
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)
0
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)
0
bar = [SOME EXPRESSION for item in some_iterable]
0

New to Communities?

Join the community