我有一个ints的列表a,介于 0 到 3000 之间len(a) = 3000。我有一个for循环遍历这个列表,在更大的数组中搜索每个元素的索引。
import numpy as np
a = [i for i in range(3000)]
array = np.random.randint(0, 3000, size(12, 1000, 1000))
newlist = []
for i in range(0, len(a)):
coord = np.where(array == list[i])
newlist.append(coord)
如您所见,coord3D 矩阵中的值等于列表中的值的坐标 x、y、z 的 3 个数组。
for有没有办法在没有循环的情况下以矢量化方式做到这一点?
输出应该是一个元组列表,每个元素对应一个a:
# each coord looks like this:
print(coord)
(array[1, ..., 1000], array[2, ..., 1000], array[2, ..., 12])
# combined over all the iterations:
print(newlist)
[coord1, coord2, ..., coord3000]
holdtom
当年话下
相关分类