python - 多线程/进程加速双循环内的函数?
问题描述
我正在尝试做这样的事情:
import skimage
def dostuff(im, [m, n]):
# im is a 2D numpy array greyscale image.
# This calculate the line profile from a given point [m,n]
# to the origin [0, 0] on the im
line = skimage.measure.profile_line(im, [m,n], [0,0])
first_two = line[:2]
return first_two
x = 20
matrix = np.zeros(2*x+1, 2*x+1, 1000)
for m in range(-x, x+1):
for n in range(-x, x+1):
result = dostuff(im, [m,n])
matrix[m, n] = result
有什么方法可以通过在 python 中使用多线程或多处理来加速这种双循环计算?
解决方案
推荐阅读
- java - Hibernate 在尝试检索数据时抛出错误(分离的实体)
- javascript - 在 React 中不会触发 play() 方法(除非有点击事件)
- angular - 根据条件添加角度模块
- java - Xpath 在 Chrome 浏览器中工作,但相同的 Xpath 在 Firefox 浏览器中不工作
- jmeter - 如何处理JMeter同一个线程组中的多用户和单用户
- vert.x - 如何在集群模式下将 Vertx RedisClient 与 Elasticache 连接
- java - 如何使用 Spring 安全性测试基于数据库的用户的 JWT 身份验证?
- python - 由于python中的一些错误,我无法重建?
- android - DropInResult 返回 null 作为响应
- python - 回调函数不会被触发