I have some simple code and I just want to count the number of distinct columns in the product of two matrices. The code is
import numpy as np
import itertools
n = 5
h = 2
M = np.random.randint(2, size=(h,n))
F = np.matrix(list(itertools.product([0,1],repeat = 5))).transpose()
product = M*F
setofcols = set()
for column in product.T:
setofcols.add(column)
print len(setofcols)
However this gives the wrong answer as all the elements of setofcols
are different even if the columns were the same. What is the right thing to do?
I will be running this with bigger values of n and h so a solution that uses as little memory as possible would be great.