MCPcopy Index your code
hub / github.com/dask/dask / moment

Function moment

dask/array/reductions.py:563–636  ·  view source on GitHub ↗

Calculate the nth centralized moment. Parameters ---------- a : Array Data over which to compute moment order : int Order of the moment that is returned, must be >= 2. axis : int, optional Axis along which the central moment is computed. The default is to

(
    a, order, axis=None, dtype=None, keepdims=False, ddof=0, split_every=None, out=None
)

Source from the content-addressed store, hash-verified

561
562
563def moment(
564 a, order, axis=None, dtype=None, keepdims=False, ddof=0, split_every=None, out=None
565):
566 """Calculate the nth centralized moment.
567
568 Parameters
569 ----------
570 a : Array
571 Data over which to compute moment
572 order : int
573 Order of the moment that is returned, must be >= 2.
574 axis : int, optional
575 Axis along which the central moment is computed. The default is to
576 compute the moment of the flattened array.
577 dtype : data-type, optional
578 Type to use in computing the moment. For arrays of integer type the
579 default is float64; for arrays of float types it is the same as the
580 array type.
581 keepdims : bool, optional
582 If this is set to True, the axes which are reduced are left in the
583 result as dimensions with size one. With this option, the result
584 will broadcast correctly against the original array.
585 ddof : int, optional
586 "Delta Degrees of Freedom": the divisor used in the calculation is
587 N - ddof, where N represents the number of elements. By default
588 ddof is zero.
589
590 Returns
591 -------
592 moment : Array
593
594 References
595 ----------
596 .. [1] Pebay, Philippe (2008), "Formulas for Robust, One-Pass Parallel
597 Computation of Covariances and Arbitrary-Order Statistical Moments",
598 Technical Report SAND2008-6212, Sandia National Laboratories.
599
600 """
601 if not isinstance(order, Integral) or order < 0:
602 raise ValueError("Order must be an integer >= 0")
603
604 if order < 2:
605 reduced = a.sum(axis=axis) # get reduced shape and chunks
606 if order == 0:
607 # When order equals 0, the result is 1, by definition.
608 return ones(
609 reduced.shape, chunks=reduced.chunks, dtype="f8", meta=reduced._meta
610 )
611 # By definition the first order about the mean is 0.
612 return zeros(
613 reduced.shape, chunks=reduced.chunks, dtype="f8", meta=reduced._meta
614 )
615
616 if dtype is not None:
617 dt = dtype
618 else:
619 dt = getattr(np.var(np.ones(shape=(1,), dtype=a.dtype)), "dtype", object)
620

Callers 1

momentMethod · 0.90

Calls 4

reductionFunction · 0.90
sumMethod · 0.45
varMethod · 0.45
onesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…