jeudi 11 mars 2021

ValueError: low >= high in np.random.randint [New Type]

import glob
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np

dataset_paths = glob.glob("dataset_characters/**/*.jpg")

cols=3
rows=3
fig = plt.figure(figsize=(10,8))
plt.rcParams.update({"font.size":14})
grid = gridspec.GridSpec(ncols=cols,nrows=rows,figure=fig)

# create a random list of images will be displayed
np.random.seed(45)
rand = np.random.randint(0,len(dataset_paths),size=(cols*rows))

# Plot example images
for i in range(cols*rows):
    fig.add_subplot(grid[i])
    image = load_img(dataset_paths[rand[i]])
    label = dataset_paths[rand[i]].split(os.path.sep)[-2]
    plt.title('"{:s}"'.format(label))
    plt.axis(False)
    plt.imshow(image) 

Error is shown below:

ValueError                                Traceback (most recent call last)
<ipython-input-9-6eacd403c46e> in <module>
     14 # create a random list of images will be displayed
     15 np.random.seed(45)
---> 16 rand = np.random.randint(0,len(dataset_paths),size=(cols*rows))
     17 
     18 # Plot example images

mtrand.pyx in numpy.random.mtrand.RandomState.randint()

_bounded_integers.pyx in numpy.random._bounded_integers._rand_int32()

ValueError: low >= high

<Figure size 720x576 with 0 Axes>

It works fine in the tutorial but it showing an error here... see the other answers for this error but didn't get the solution...trying to implement data visualization here




Aucun commentaire:

Enregistrer un commentaire