尝试访问 numpy 中的单个数组元素会访问一个序列

Trying to access a single array element in numpy accesses a sequence instead

我正在尝试制作一个程序,该程序可以随机获取各种图像的部分,然后将它们加回一起,但是当我随后尝试访问单个数组元素时,它会以序列的形式出现。

def select_from_image(img):
    factor=rng.uniform(1/20,1/10)
    width=int(np.floor(img.shape[1]*np.sqrt(factor)))
    height=int(np.floor(img.shape[0]*np.sqrt(factor)))
    x=rng.randint(0,img.shape[1]-1-width)
    y=rng.randint(0,img.shape[0]-1-height)
    return img[y:y+height-1:,x:x+width-1:]
imgs=[]
for i in range(len(paths)):
    imgs.append(ig.imread(paths[i]))
selection=[]
for img in imgs:
    selection.append(select_from_image(img))

我已经进行了一些测试并推断出问题出在 "select_from_image(img)",但我就是无法确定。 这是一个示例输出: https://imgur.com/a/1Cs8i4J

欢迎任何帮助!

我发现了问题,它(完全)不是代码。 我使用的图像不是单色的(这意味着 imread 生成的数组中的每个元素都有三个值而不是一个),所以如果有人遇到这样的问题并得到 confused/frustrated 读这个: https://brohrer.github.io/convert_rgb_to_grayscale.html 它对我帮助很大!