I have a binary matrix of shape N,M, and I want an efficient way to transform it to chromosome, that is, given a row I need a function that returns the indexes of non-zero elements, for example given the row [1,1,0,0,0,0,0,0,1] the function should return [0,1,8], this could be done with np.flatnonzero for example. I need to apply this transformation to all rows and return a flatten vector representing the binary matrix, for example
P = np.array([[1,1,0,0,0,0,0,0,1], [0,0,1,1,1,1,0,0,0], [0,0,0,0,0,0,1,1,0]])
should be transformed to [018234567]