0

I am writing to ask what is the difference between using a Fisher-Yates shuffling algorithm to shuffle a dataset compared to using np.random.permutation just like in the following code snippet:

X.shape[1] # number of training examples

permutation = list(np.random.permutation(m))
shuffled_X = X[:, permutation]
shuffled_Y = Y[:, permutation].reshape((1,m))
Liam
  • 27,717
  • 28
  • 128
  • 190
Lydia
  • 1
  • 1
  • 2
  • Possible duplicate of [shuffle vs permute numpy](https://stackoverflow.com/questions/15474159/shuffle-vs-permute-numpy) – wildwilhelm May 06 '19 at 11:53
  • Thanks. I'm still not quite sure of the difference. Could you please explain? – Lydia May 06 '19 at 13:00
  • Sure. [The source for `permutation`](https://github.com/numpy/numpy/blob/master/numpy/random/mtrand/mtrand.pyx#L4922) shows that numpy just sets up a range and then calls `shuffle`, so the underlying algorithm is Fisher-Yates. The difference between permutation and shuffle is that you can call the former with either an array or an integer, and that the latter does its work in-place. – wildwilhelm May 07 '19 at 13:27

0 Answers0