-1

Im a doing an experiment several times (monte carlo simulation). In the experiment I select a random number of columns and do the calculations with the selected columns. Initially I have to the experiment with 5 columns, and repeat it 100 times. My dataframe has 4000 columns.

I summarized the code, and I am only showing the part of the code which select randomly the columns. Please take into account that I repeat this procedure 100 times. The part of the code is as follows:

 import numpy as np
 import pandas as pd
 df = pd.DataFrame(np.random.choice([0.0, 0.05], size=(1000,1000)))
 rand_cols = np.random.permutation(df.columns)[0:5]
 df2 = df[rand_cols].copy()

My question is the following:

Does the function np.random.permutation work with replacement or without replacement?

The reason I ask this question it is because I run the code several times, at the moment it is 100 times. I will probably run the code more time and I need to know if the function works with replacement. If the function does not work with replacement, is there another function that does the same and work with replacement?

Thanks

asdfg_rocks
  • 117
  • 1
  • 11
Jonathan Budez
  • 226
  • 1
  • 3
  • 12
  • I think you can find this question and the respective answer useful: https://stackoverflow.com/questions/15474159/shuffle-vs-permute-numpy – Hirabayashi Taro Apr 04 '19 at 12:29

1 Answers1

0

From the documentation examples it is clear that numpy.random.permutation doesn't replace from your selection set.

newkid
  • 1,368
  • 1
  • 11
  • 27
  • I am not sure if I fully understood your answer, but basically what I need is the function to work with replacement. For instance, if I pick 5 columns every simulation, I would expect to one of the columns to be repeated at least in one of the simulations. – Jonathan Budez Apr 04 '19 at 14:25
  • This you cannot do with just `permutation`. But you can do it with just `choice`. I think that would be a different SO question. This one just asks about how `permutation` works. – newkid Apr 04 '19 at 14:29