MCPcopy Create free account
hub / github.com/numpy/numpy / nancumprod

Function nancumprod

numpy/lib/nanfunctions.py:885–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. .. versionad

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

_replace_nanFunction · 0.85
cumprodMethod · 0.80

Tested by

no test coverage detected