'Python Shuffling a Numpy Array and List That Have Sorted Elements

I am training a CNN, reading images from files and creating a numpy array from these images. I also create a list that stores class names (which is equal to file names). Since my code reads files by their order, my dataset is not shuffled. So I can't get good accuracy values. I want to shuffle images but I want to shuffle the class names without losing their link. How can I do that? Here is the code for reading images below.

def create_dataset(img_folder):
    a = 0
    img_data_array=[]
    class_name=[]
    for dir1 in os.listdir(img_folder):
        for file in os.listdir(os.path.join(img_folder, dir1)):
            a+=1
            image_path= os.path.join(img_folder, dir1,  file)
            image= cv2.imread( image_path, cv2.COLOR_BGR2RGB)
            try:
              image=cv2.resize(image, (img_height, img_width),interpolation = cv2.INTER_AREA)
            except:
              break
            image=np.array(image)
            image = image.astype('float32')
            image /= 255 
            img_data_array.append(image)
            class_name.append(dir1)
    print (a)
    return img_data_array, class_name


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source