我花了很多时间来加速下面的脚本,但我不能。你能帮帮我还是建议加快速度?这是我的密码
import numpy as np
import time
#Unchange
input = np.random.randn(300,400,500)
step_x = 30
step_y = 40
step_z = 50
lst_x = np.arange(0, input.shape[0] + step_x, step_x)
lst_y = np.arange(0, input.shape[1] + step_y, step_y)
lst_z = np.arange(0, input.shape[2] + step_z, step_z)
results = np.zeros((input.shape))
t0 = time.time()
for i in range(len(lst_x)):
for j in range(len(lst_y)):
for k in range(len(lst_z)):
xx= lst_x[i]
yy= lst_y[j]
zz= lst_z[k]
patch = input[xx : xx + step_x, yy : yy + step_y, zz : zz + step_z]
patch_added = np.random.randn(patch.shape[0],patch.shape[1],patch.shape[2]) + patch
results[xx : xx + step_x, yy : yy + step_y, zz : zz + step_z] += patch_added
print ('Time consumption: ', time.time()-t0)
你可以在网上跑步
https://repl.it/repls/PleasingGhostwhiteNetworking
目前,repl.it需要11秒。你能在python 3中使它更快吗?
更新:
我有一个原始的数组输入是3d数组。从数组中,我将提取大小为30x40x50的补丁并处理该补丁。之后,将处理的修补程序分配到结果数组中,其位置与
input