function Pc = conditional_distribution(P,d)
% Return conditional distribution, conditioned on dimension d, in same shape as input matrix. 

nd = ndims(P);
marginalize_dims = 1:nd;
marginalize_dims(d) = [];
D = diag(1./( sumdims( P , marginalize_dims ) ) );

Pc = multiprod(P, D, d, [1,2] );


end