Given a matrix, the goal is to ensure all the values in each column occur at least once, while at the same time doing so requiring the least possible amount of rows. Fastest solution wins.
Note: a value in one column (e.g. 1) is considered different from the same value in another column.
Expected output: an array/list/series of row indices that retain all unique values across all columns.
Example data:
import numpy as np
import pandas as pd
np.random.seed(42)
num_rows = 10000
num_cols = 200
max_uniq_values = 10
data = pd.DataFrame({i: np.random.randint(0, max_uniq_values, num_rows)
for i in range(num_cols)})
# or python
# data = [np.random.randint(0, max_uniq_values, num_rows).tolist()
# for i in range(num_cols)]
Minimal example (num_rows=5, num_cols=2, max_uniq_values=4)
Input:
| 0 1
--------
0 | 1 1
1 | 2 2
2 | 3 4
3 | 3 3
4 | 4 4
Expected output:
[0, 1, 3, 4]
Additionally:
- Benchmark will happen on a 2015 Macbook Pro with CPU Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz.
- Restricted to use 1 core.
- External libraries allowed
- Blind test will be done on 10 random seeds (the same ones for each solution)
SELECT
the least number of rows to have unique values in each row for all columns. I definitely did not get that from your Question. \$\endgroup\$