MCPcopy Create free account
hub / github.com/PythonOT/POT / unif

Function unif

ot/utils.py:228–248  ·  view source on GitHub ↗

r""" Return a uniform histogram of length `n` (simplex). Parameters ---------- n : int number of bins in the histogram type_as : array-like array of the same type of the expected output (numpy/pytorch/jax) Returns ------- h : array-like, shape (n,)

(n, type_as=None)

Source from the content-addressed store, hash-verified

226
227
228def unif(n, type_as=None):
229 r"""
230 Return a uniform histogram of length `n` (simplex).
231
232 Parameters
233 ----------
234 n : int
235 number of bins in the histogram
236 type_as : array-like
237 array of the same type of the expected output (numpy/pytorch/jax)
238
239 Returns
240 -------
241 h : array-like, shape (n,)
242 histogram of length `n` such that :math:`\forall i, \mathbf{h}_i = \frac{1}{n}`
243 """
244 if type_as is None:
245 return np.ones((n,)) / n
246 else:
247 nx = get_backend(type_as)
248 return nx.ones((n,), type_as=type_as) / n
249
250
251def clean_zeros(a, b, M):

Calls 2

get_backendFunction · 0.85
onesMethod · 0.45