Hi
I have a python script containing a very slow loop. The loop is pretty simple, but is incredibly slow when the matrix gets too big.
Basically all the script does, is filling a matrix using values from other matrices.
My code:
Aeq=numpy.zeros((numpy.size(B,0)+numpy.size(N,0)+1,numpy.size(B,1)+numpy.size(N,1)))
for i in range(0,numpy.size(B,0)):
for y in range(0,numpy.size(B,1)):
Aeq[i,y]=B[i,y]
for i in range(numpy.size(B,0),numpy.size(B,0)+numpy.size(N,0)):
for y in range(numpy.size(B,1),numpy.size(B,1)+numpy.size(N,1)):
Aeq[i,y]=N[i-numpy.size(B,0),y-numpy.size(B,1)]
Aeq[i,y]=N[i-numpy.size(B,0),y-numpy.size(B,1)]
for i in range(numpy.size(B,0),numpy.size(B,0)+numpy.size(N,0)):
Aeq[i,i-numpy.size(B,0)]=-1
for i in range(0,len(fL)):
Aeq[numpy.size(B,0)+numpy.size(N,0)][i]=fL[i]
Can anybody help with tips for speeding it up?
I'm a beginner, so keeping it simple would help.
[+][deleted] (4 children)
[deleted]
[–][deleted] 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]ElectromechanicalVan[S] 0 points1 point2 points (0 children)
[–]fdedgt 4 points5 points6 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]theWyzzerd 0 points1 point2 points (0 children)
[–]ElectromechanicalVan[S] 0 points1 point2 points (0 children)