Maybe some of you have an idea: I'm looking for a way to implement a discrete multidimensional probability distrbution that is only sparsely populated but can still efficiently be marginalized: stackoverflow.com/questions/78323703
@flawr how bad would it be to use a custom class that contains the values as a list and the indices as sorted tuples? In other words, how efficient must efficient marginalising be? Access to items during marginalization would be worse.
I'm thinking you could just loop over index-value pairs and construct the sum object on the fly in O(N).
Actually, dict rather than list so you can ignore zeroes more easily. Alternatively, an auxiliary set of all indices.