【发布时间】:2021-09-28 14:25:10
【问题描述】:
我有以下代码:
import numpy as np
my_array = np.zeros((42, 123, 2021))
assert another_array.shape == (42, 123)
for i in range(42):
for j in range(123):
my_array[i, j, another_array[i, j]] = 1
假设 another_array 的值保持在正确的范围内(即 another_array 的值是 0 到 2020 之间的整数)。
我想摆脱两个 for 循环。有没有办法对这样的东西进行矢量化?
【问题讨论】:
标签: python numpy vectorization