I have the output of a Markov transition table, which is a list of 59 lists each with 59 floats. I want to invert each of the non-0 floats, and then normalise the output so that again I have a list of probabilities which add up to 1.
I have read the textbook on list comprehensions, and that seems relevant, but I can't for the life of me understand how to implement it.
The list of lists is m
for i in range(59):
[1/item for item in m[i] if item > 0.]
i += 1
This runs, but it doesn't change m
. Am I wrong to be using item
in this code? Should I be using some other reference?