以下是我的代碼。自無限時間(幾乎一天)開始運行。我無法弄清楚是因爲有很多循環還是因爲有無止境的循環。以下是我的代碼:自無限時間運行代碼
mat1 = np.zeros((1024,1024,360),dtype=np.int32)
k = 498
gamma = 0.00774267
R = 0.37
g = np.zeros(1024)
g[0:512] = np.linspace(0,1,512)
g[513:] = np.linspace(1,0,511)
pf = np.zeros((1024,1024,360))
pf1 = np.zeros((1024,1024,360))
for b in range(0,1023) :
for beta in range(0,359) :
for a in range(0,1023) :
pf[a,b,beta] = (R/(((R**2)+(a**2)+(b**2))**0.5))*mat[a,b,beta]
pf1[:,b,beta] = np.convolve(pf[:,b,beta],g,'same')
for x in range(0,1023) :
for y in range(0,1023) :
for z in range(0,359) :
for beta in range(0,359) :
a = R*((-x*0.005)*(sin(beta)) + (y*0.005)*(cos(beta)))/(R+(x*0.005)*(cos(beta))+(y*0.005)*(sin(beta)))
b = z*R/(R+(x*0.005)*(cos(beta))+(y*0.005)*(sin(beta)))
U = R+(x*0.005)*(cos(beta))+(y*0.005)*(sin(beta))
l = math.trunc(a)
m = math.trunc(b)
if (0<=l<1024 and 0<=m<1024) :
mat1[x,y,z] = mat[x,y,z] + (R**2/U**2)**pf1[l,m,beta]
import matplotlib.pyplot as plt
from skimage.transform import iradon
import matplotlib.cm as cm
from PIL import Image
I8 = (((mat1 - mat1.min())/(mat1.max() - mat1.min())) * 255.9).astype(np.uint8)
img = Image.fromarray(I8)
img.save("M4.png")
im = Image.open("M4.png")
im.show()
歡迎來到暫停問題。也許你可以添加一些日誌記錄並確定程序在哪裏花費時間。 – jgritty
如果在循環內添加日誌記錄(打印迭代器)以跟蹤正在進行的進程,會發生什麼情況?那將是我的第一步。 – 0x24a537r9
幾乎一天不是無限的。 –