shuffled_X = X[:, permutation]

in the programming assignment I don’t understand the line:
shuffled_X = X[:, permutation]

I understand how permutation is generated through the line : permutation = list(np.random.permutation(m))
but I don’t see how the permutation we’ve generated is applied successfully to produce shuffled_X (and then shuffled_Y)

could you help me please? thanks much

This line shuffled_X = X[:, permutation] means shufled_X list is taking all the elements of X from index 0 to index=permutation.

Just a few addition…

What we want to do is to shuffle X. The size of X is (12288, 148). In this case, the number of training example is 148.
Here is the step.

  1. At first, we create a list of “shuffled” indexes. Since we have 148 example, we create a permutation of 148 with np.random.permutation(). Then, you can get a permutation in a numpy.array. (It’s a kind of random order of 0~148, like ([79, 99, 110, 0, 145,…]).
  2. We make “numpy array” to “list” to be indexes.
  3. Then, as Gent explained, we can easily pick up samples from X according to this permutation list.

So, this is one of way to get shuffled data.

many thanks, that’s very helpful!