ojp
ojp

Reputation: 1033

randomly shuffle 3d numpy array on specific axis

I have loaded 66 csv files, each containing a time series of 5000 time steps and three features with the following code:

rms = glob(sims_dir+"/rms*.csv")
df = [pd.read_csv(f).values for f in rms]
data = np.asarray(df)
data.shape
(66, 5004, 3)

Here my first axis of size 66 are my 66 unique time series. I would like to shuffle my array so that my first dimension (66) is of random order, but aren't exactly sure of the best way to do this... an alternative approach could be to load each csv randomly from its directory but I was wondering how this could be achieved in numpy.

Upvotes: 0

Views: 284

Answers (1)

tstanisl
tstanisl

Reputation: 14147

Use np.random.shuffle(data). This function is dedicated for this task. See np.random.shuffle

Upvotes: 1

Related Questions