ValueError:: low >= high

Viewed 883

I am trying to resolve === Help me to fix this

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()

In line = r = np.random.randint(0 , cells.shape[0] , 1) there is error = ValueError:: low >= high

1 Answers

You are using np.random.randint(low=0, high=cells.shape[0], size=1).

The error indicates that low >= high which suggests cells.shape[0] == 0. np.random.randint picks a number in the range [low,high) so there are no possible numbers to pick, which causes the error.

To debug this check print(cells.shape) and even print(cells) to ensure the values in cells are what you expect.

You could also add a check before the for loop:

if cells.shape[0] > 0:

Related