Pythonic Way To Get Index,column For Value == 1
I currently have a MxN dataframe which contains a solution to an optimization problem. 'Active' i,j for i in {M} and j in {N} pairs are represented by 1 and 'inactive' pairs by 0.
Solution 1:
>>> import numpy
>>> a = numpy.array([[1, 0, 1], [0, 1, 1], [0, 1, 0]])
>>> numpy.transpose(numpy.nonzero(a))
array([[0, 0],
[0, 2],
[1, 1],
[1, 2],
[2, 1]])
Post a Comment for "Pythonic Way To Get Index,column For Value == 1"