I would like to start in column 0 of K and choose one of the 4 rows (users) to change their value to zero (unavailable). Then for column 1 we will do the same, but the previous row cannot be chosen, so it is sampling without replacement. So for the fourth choice there is only one default option, then a zero has been assigned to all rows with the other values remaining the same as k.
This process needs to be repeated again until the end of the vector, which may not be proportional to the number of rows, and hence some rows "miss out" like above where we have 4 rows but n=7. This last part makes me think I need to use a while loop, which I am not too good with, however perhaps there are some pandas or sampling functions that can help with this? Hints over solutions also welcome.
Using the following data, either as an array or converted to a data frame:
n = 7
k = np.array([
np.ones(n),
np.ones(n),
3*np.ones(n),
7*np.ones(n)])
K = pd.DataFrame(k)
Alternatively I want to create a random matrix of the form:
np.array([
[1,0,0,0,0,0,0],
[0,0,1,0,0,0,1]
[0,1,0,0,0,1,0]
[0,0,0,1,1,0,0])
such that there are 4 users and therefore for the first 4 weeks each user has just one true value, the process starts again for period 5. Note user 1 only one true value since we only look at 7 periods rather than 2*4=8. Then overlay this on k and change those values to zero to create the required matrix.
Aucun commentaire:
Enregistrer un commentaire