我有以下 python 代码片段:
import numpy as np
# Some random array
x = np.random.rand(34, 176, 256)
# Get some indexes
pos_idx = np.argwhere(x > 0.5)
# Sample some values from these indexes
seeds = pos_idx[np.random.choice(pos_idx.shape[0], size=5, replace=False), :]
# Now create another array
y = np.zeros_like(x, np.uint8)
y[seeds] = 1
最后一行给出了如下错误:
index 77 is out of bounds for axis 0 with size 34
但我不确定这是怎么发生的,因为所有采样索引都应该有效,因为它们是一个子集。
MYYA
哆啦的时光机
慕码人2483693
相关分类