I created an array of numbers of column size d
, where the numbers are different combinations of set(p)
. Next, I want to delete the rows where there are more instances of a number than there were in p
. I can do it with a for
loop, here is my code:
import numpy as np
import itertools as it
from collections import Counter
p = [0,0,0,1,1,1,1,2,2,2,2,2,3,3,3,4,4,4,4,4,5,5,5]
assert (len(set(p)) != 1)
cnt = Counter(p)
pos = np.array(list(it.product(set(p), repeat=d)))
ds = []
for i in range(len(pos)):
for j, k in cnt.items():
if len(np.where(pos[i] == j)[0]) > k:
ds.append(i)
pos = np.delete(pos, ds, axis=0)
I am looking for a faster way to do this. Thank you!