Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

Shuffling multi-dimensional numpy array in python

I have a multi-dimensional NumPy array, that is acting as input data to my neural network. I have 2115 different (6,100,60) samples. I want to shuffle my data - rearrange the order - of the 2115 (6,100,60) samples. I want to make sure the channels, columns, and rows of (6,100,60) all stay in place - i.e., I only want to shuffle the location (in the array) of these 2115 samples.

I am not sure how to do this - any help would be appreciated.

Thank you.

question from:https://stackoverflow.com/questions/65923994/shuffling-multi-dimensional-numpy-array-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can shuffle the sample number (assuming first dimension) then reindex:

order = np.random.permutation(np.arange(2115))

data = data[order]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...