Numpy shuffle multidimensional array by row only, keep column order unchanged

后端 未结 6 640
不思量自难忘°
不思量自难忘° 2020-12-05 12:52

How can I shuffle a multidimensional array by row only in Python (so do not shuffle the columns).

I am looking for the most efficient solution, because my ma

6条回答
  •  执念已碎
    2020-12-05 13:24

    I have a question on this (or maybe it is the answer) Lets say we have a numpy array X with shape=(1000,60,11,1) Also suppose that X is an array of images with size 60x11 and channel number =1 (60x11x1).

    What if I want to shuffle the order of all these images, and to do that I'll use shuffling on the indexes of X.

    def shuffling( X):
     indx=np.arange(len(X))          # create a array with indexes for X data
     np.random.shuffle(indx)
     X=X[indx]
     return X
    

    Will that work? From my knowledge len(X) will return the biggest dimension size.

提交回复
热议问题