【发布时间】:2020-07-09 14:53:02
【问题描述】:
我有一个来自 tensor.max() 操作的 Numpy 2D 数组 (4000,8000),它存储 4D 数组 (30,4000,8000,3) 的第一个维度的索引。我需要获取一个 (4000,8000,3) 数组,该数组使用这组图像的索引并提取 2D max 数组中每个位置的像素。
A = np.random.randint( 0, 29, (4000,8000), dtype=int)
B = np.random.randint(0,255,(30,4000,8000,3),dtype=np.uint8)
final = np.zeros((B.shape[1],B.shape[2],3))
r = 0
c = 0
for row in A:
c = 0
for col in row:
x = A[r,c]
final[r,c] = B[x,r,c]
c=c+1
r=r+1
print(final.shape)
有没有矢量化的方式来做到这一点?我正在使用循环与 RAM 使用作斗争。谢谢
【问题讨论】:
标签: arrays numpy pytorch indices