def prob_mv_grid(bins, cdf, axis=(-1)):
 if (not isinstance(bins, np.ndarray)):
  bins = lmap(np.asarray, bins)
  n_dim = len(bins)
  bins_ = []
  if all((lmap(np.ndim, bins) == np.ones(n_dim))):
   for d in range(n_dim):
    sl = ([None] * n_dim)
    sl[d] = slice(None)
    bins_.append(bins[d][sl])
 else:
  n_dim = bins.shape[0]
  bins_ = bins
 print(len(bins))
 cdf_values = cdf(bins_)
 probs = cdf_values.copy()
 for d in range(n_dim):
  probs = np.diff(probs, axis=d)
 return probs

def prob_mv_grid ( bins , cdf , axis = ( - 1 ) ) : if ( not isinstance ( bins , np . ndarray ) ) : bins = lmap ( np . asarray , bins ) n_dim = len ( bins ) bins_ = [ ] if all ( ( lmap ( np . ndim , bins ) == np . ones ( n_dim ) ) ) : for d in range ( n_dim ) : sl = ( [ None ] * n_dim ) sl [ d ] = slice ( None ) bins_ . append ( bins [ d ] [ sl ] ) else : n_dim = bins . shape [ 0 ] bins_ = bins print ( len ( bins ) ) cdf_values = cdf ( bins_ ) probs = cdf_values . copy ( ) for d in range ( n_dim ) : probs = np . diff ( probs , axis = d ) return probs
helper function for probability of a rectangle grid in a multivariate distribution how does this generalize to more than 2 variates ? bins : tuple tuple of bin edges .