【发布时间】:2020-02-27 17:32:42
【问题描述】:
我想用 2 初始化 2D numpy 数组,用于列小于行 + x(x 是参数)的条带,用 3 用于列大于行 + y 的条带(假设 y > x) 像这样:
有没有比蛮力嵌套循环更快的方法:
pos_path = np.zeros((rows + 1, cols + 1), dtype=np.int32)
rows = 384;
cols = 288;
x = -12
y = 23
for r in range(0, rows+1):
for c in range(0, cols + 1):
if c < r + x:
pos_path[r, c] = 2
elif c > r + y:
pos_path[r, c] = 3
【问题讨论】:
标签: python python-3.x numpy vectorization