MCPcopy Index your code
hub / github.com/numpy/numpy / nancumprod

Function nancumprod

numpy/lib/_nanfunctions_impl.py:886–944  ·  view source on GitHub ↗

Return the cumulative product of array elements over a given axis treating Not a Numbers (NaNs) as one. The cumulative product does not change when NaNs are encountered and leading NaNs are replaced by ones. Ones are returned for slices that are all-NaN or empty. Parameters

(a, axis=None, dtype=None, out=None)

Source from the content-addressed store, hash-verified

884
885@array_function_dispatch(_nancumprod_dispatcher)
886def nancumprod(a, axis=None, dtype=None, out=None):
887 """
888 Return the cumulative product of array elements over a given axis treating Not a
889 Numbers (NaNs) as one. The cumulative product does not change when NaNs are
890 encountered and leading NaNs are replaced by ones.
891
892 Ones are returned for slices that are all-NaN or empty.
893
894 Parameters
895 ----------
896 a : array_like
897 Input array.
898 axis : int, optional
899 Axis along which the cumulative product is computed. By default
900 the input is flattened.
901 dtype : dtype, optional
902 Type of the returned array, as well as of the accumulator in which
903 the elements are multiplied. If *dtype* is not specified, it
904 defaults to the dtype of `a`, unless `a` has an integer dtype with
905 a precision less than that of the default platform integer. In
906 that case, the default platform integer is used instead.
907 out : ndarray, optional
908 Alternative output array in which to place the result. It must
909 have the same shape and buffer length as the expected output
910 but the type of the resulting values will be cast if necessary.
911
912 Returns
913 -------
914 nancumprod : ndarray
915 A new array holding the result is returned unless `out` is
916 specified, in which case it is returned.
917
918 See Also
919 --------
920 numpy.cumprod : Cumulative product across array propagating NaNs.
921 isnan : Show which elements are NaN.
922
923 Examples
924 --------
925 >>> import numpy as np
926 >>> np.nancumprod(1)
927 array([1])
928 >>> np.nancumprod([1])
929 array([1])
930 >>> np.nancumprod([1, np.nan])
931 array([1., 1.])
932 >>> a = np.array([[1, 2], [3, np.nan]])
933 >>> np.nancumprod(a)
934 array([1., 2., 6., 6.])
935 >>> np.nancumprod(a, axis=0)
936 array([[1., 2.],
937 [3., 2.]])
938 >>> np.nancumprod(a, axis=1)
939 array([[1., 2.],
940 [3., 3.]])
941
942 """
943 a, mask = _replace_nan(a, 1)

Callers

nothing calls this directly

Calls 2

_replace_nanFunction · 0.85
cumprodMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…