1

I am using train_test_split. My training set, X[], is an array of file paths. Then I have another array y[] that is composed on one hot encoded labels. They are related by the array row index. So if I pass X it looks like this:

Index path

4, data\djip2\DJIP2.5844MHz.10MSPS.fc32.2016-07-01_000000000001.npy

20, data\taigentank\USRP-2_420GHz-1MSps-1MHztaigentank1_000000000000.npy

2, data\866_300_1\USRP-866_300MHz-1MSps-1MHz_lte_1_000000000002.npy

And y[] looks like this:

Index label

4, 00000001

20, 00000010

2, 01000000

These arrays are then passed to a batch generator after being randomized. At the batch generator I need to make sure each X array value can be mapped back to a y[] array label.

So, I want to be able to get the X array indexes which are now in a random order like:

2, path

4, path

20, path

And pass them to another function in this order. I need the indices because I need to pass the path as well as its associated label. Is there a simple way to do this with numpy?

1 Answer 1

1

One solution might be:

n = range(numberOfInstances)

which creates a list of integers like [0,1,2,3,4...numberOfInstances-1]. Then shuffle the list

random.shuffle(n)

Save this list as a numpy array

n_np = np.array(n)

and finally reorder your data and groundtruth accordingly like

y = y[n_np]
x = x[n_np]

which should reorder both arrays in regarding the same way.

I hoipe this helps :)! I am a little bit confused why you have an unordered sequence of IDs which somehow are shuffled again....

Sign up to request clarification or add additional context in comments.

1 Comment

The reason is I am doing this labelbinarizer = LabelBinarizer() X = train.path y = labelbinarizer.fit_transform(train.word) X, Xt, y, yt = train_test_split(X, y, test_size=0.3, stratify=y) -- where X is a array of paths and Y is array of labels. The split funcation associates the right labels to each path and makes a random dataset so on each epoc the samples come in at diffrent orders to

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.