2021年3月13日星期六

Numpy.random,shuffle() did not work as expected

I want to shuffle numpy array row wise and default axis in numpy.random.shuffle() is 0. But in my case, it magically shuffles column wise.

Cats = Path("./dog_pictures")  Dogs = Path("./cat_pictures")  labels = {Cats: 0, Dogs: 1}  training_data = np.array([])    for label in labels:    for img in label.iterdir():           for img in images:           read_image = cv2.imread(f"{img}", cv2.IMREAD_GRAYSCALE)           resized_image = cv2.resize(read_image, (50, 50))           training_data = np.append(training_data,np.array([resized_image, np.eye(2)[self.labels[label]]], dtype=object))  np.random.shuffle(training_data)  np.save("training_data13.npy", training_data)      array = np.load("training_data13.npy", allow_pickle=True)  print(array[10:])  

Output:

[array([1., 0.]) array([1., 0.]) array([1., 0.])   array([[44, 56, 64, ..., 52, 49, 58],          [54, 65, 55, ..., 58, 70, 51],          [45, 52, 48, ..., 58, 83, 49],          ...,          [63, 45, 45, ..., 87, 80, 83],          [50, 55, 63, ..., 91, 71, 74],          [50, 64, 60, ..., 93, 77, 72]], dtype=uint8) array([0., 1.])   array([[255, 255, 255, ..., 255, 255, 255],          [255, 255, 255, ..., 255, 255, 255],          [255, 254,  89, ..., 255, 255, 255],          ...,          [255, 255, 255, ..., 255, 255, 255],          [255, 255, 255, ..., 255, 255, 255],          [255, 255, 255, ..., 255, 255, 255]], dtype=uint8) array([1., 0.])   array([0., 1.]) array([0., 1.])  

I could not pinpoint the problem. Thanks in Advance

https://stackoverflow.com/questions/66620419/numpy-random-shuffle-did-not-work-as-expected March 14, 2021 at 10:05AM

没有评论:

发表评论