【问题标题】:ValueError:: low >= highValueError:: 低 >= 高
【发布时间】:2021-10-01 10:28:50
【问题描述】:

我正在尝试解决 === 帮我解决这个问题

plt.figure(1 , figsize = (15 , 9))
n = 0 
for i in range(49):
    n += 1 
    r = np.random.randint(0 , cells.shape[0] , 1)
    plt.subplot(7 , 7 , n)
    plt.subplots_adjust(hspace = 0.5 , wspace = 0.5)
    plt.imshow(cells[r[0]])
    plt.title('{} : {}'.format('Infected' if labels[r[0]] == 1 else 'Unifected' ,
                               labels[r[0]]) )
    plt.xticks([]) , plt.yticks([])
    
plt.show()

排队= r = np.random.randint(0 , cells.shape[0] , 1) 有错误 = ValueError:: low >= high

【问题讨论】:

  • cells 中有什么内容?哪一行给出了错误?
  • cells.shape[0] == 0?

标签: python pandas dataframe


【解决方案1】:

您正在使用np.random.randint(low=0, high=cells.shape[0], size=1)

错误表明low >= high 暗示cells.shape[0] == 0np.random.randint[low,high) 范围内选择一个数字,因此没有可能选择的数字,这会导致错误。

要调试此检查 print(cells.shape) 甚至 print(cells) 以确保 cells 中的值符合您的预期。

您还可以在for 循环之前添加检查:

if cells.shape[0] > 0:

【讨论】:

    猜你喜欢
    • 2021-08-07
    • 2022-12-17
    • 2013-04-12
    • 2015-06-09
    • 2012-09-08
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多