0

chooseMatrix creates an n matrix with unique rows with m ones in each row and the rest zeros.

I couldn't find any direct form of replacing this function in python with NumPy.

What I did that solved my problem, but it's inefficient because values are not treated as unique by itertools:

import numpy as np
from itertools import permutations

myset = set(i for i in permutations([0, 0, 1, 1]))
matrix = np.matrix(list(myset))
print(matrix)

output:
 matrix([[1, 0, 1, 0],
        [1, 1, 0, 0],
        [1, 0, 0, 1],
        [0, 1, 1, 0],
        [0, 1, 0, 1],
        [0, 0, 1, 1]])

1 Answers1

0

It apears that simply have an solution:

>>> from sympy.utilities.iterables import multiset_permutations
>>> list(multiset_permutations([1,1,1]))
[[1, 1, 1]]
>>> list(multiset_permutations([1,1,2]))
[[1, 1, 2], [1, 2, 1], [2, 1, 1]]

found in: permutations with unique values