Hi there.
How to increase speed of access element in 2 dimension array?
with matrix size 1000x1000
each creation of sum matrix take about 1 second.
I find the problem is in slow access to the element of list of list
what is occur in this line
I tried use array from numpy with same speed.
--- calcCMS took 0.975945949554 ---
--- calcCMS took 0.898028850555 ---
How to increase speed of access element in 2 dimension array?
the code is unreadable.
how to remove it and past normal code?
How to increase speed of access element in 2 dimension array?
with matrix size 1000x1000
each creation of sum matrix take about 1 second.
I find the problem is in slow access to the element of list of list
what is occur in this line
matrix2[y][x] = min(matrix2[upperm][x-1], matrix2[upperm][x], matrix2[upperm][x+1]) + matrix1[y][x]complete example below the message
I tried use array from numpy with same speed.
--- calcCMS took 0.975945949554 ---
--- calcCMS took 0.898028850555 ---
How to increase speed of access element in 2 dimension array?
import time from mypkg.mytimer import timer import random TIMERS = True m = 1000 n = 1000 seam = 100 matrix1 = [[0 for x in range(n)] for y in range(m)] # E matrix2 = [[0 for x in range(n)] for y in range(m)] # CMS for i in range(seam): for y in range(m): for x in range(n): matrix1[y][x] = random.randint(1,100) for x in range(n): matrix2[0][x] = matrix1[0][x] if TIMERS: starttimer = time.time() for y in range(1,m): upperm = y-1 matrix2[y][0] = min(matrix2[upperm][0], matrix2[upperm][1]) + matrix1[y][0] matrix2[y][n-1] = min(matrix2[upperm][n-2], matrix2[upperm][n-1]) + matrix1[y][n-1] for x in range(1,n-1): matrix2[y][x] = min(matrix2[upperm][x-1], matrix2[upperm][x], matrix2[upperm][x+1]) + matrix1[y][x] if TIMERS: timer(starttimer,"calcCMS")
the code is unreadable.
how to remove it and past normal code?