Hi, good question.
Let us first assume that you do not have any extra whitespaces present. If this is the case then check out the following piece of code:
with open('file') as f:
w, h = [int(x) for x in next(f).split()] # read first line
array = []
for line in f: # read rest of lines
array.append([int(x) for x in line.split()])
However, this can be further simplified and compressed. That last for loop can be put into a nested list, right?
Check it out here:
with open('file') as f:
w, h = [int(x) for x in next(f).split()]
array = [[int(x) for x in line.split()] for line in f]
This should solve your problem, let me know if you need anything else!