C2W2 Assignment - Need explanation for a couple of lines of code

Hey there!
I saw this chunk of code in the beginning of Course 2 Week 2 assignment, and I am unable to understand what’s happening here, and how is it happening.

image

I’ve seen the documentation, and once replicated this on my own with a 4x5 matrix, but I still don’t understand.

Could you please help me understand here how we’re shuffling Y? [I specifically don’t get the reshaping part]

Thank you in advance!

“permutation” will be a list of all of the integers from 0 to m-1, in random order.

Then “permutation” is used to index each column of X (and Y), and copy it into a new “shuffled” variable. The same permutation is used for X and Y so that the labels continue to match up with their examples.

1 Like