Return the cumulative sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros. Zeros are returned for slices that are all-NaN or empty. Parameters --
(a, axis=None, dtype=None, out=None)
| 815 | |
| 816 | @array_function_dispatch(_nancumsum_dispatcher) |
| 817 | def nancumsum(a, axis=None, dtype=None, out=None): |
| 818 | """ |
| 819 | Return the cumulative sum of array elements over a given axis treating Not a |
| 820 | Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are |
| 821 | encountered and leading NaNs are replaced by zeros. |
| 822 | |
| 823 | Zeros are returned for slices that are all-NaN or empty. |
| 824 | |
| 825 | Parameters |
| 826 | ---------- |
| 827 | a : array_like |
| 828 | Input array. |
| 829 | axis : int, optional |
| 830 | Axis along which the cumulative sum is computed. The default |
| 831 | (None) is to compute the cumsum over the flattened array. |
| 832 | dtype : dtype, optional |
| 833 | Type of the returned array and of the accumulator in which the |
| 834 | elements are summed. If `dtype` is not specified, it defaults |
| 835 | to the dtype of `a`, unless `a` has an integer dtype with a |
| 836 | precision less than that of the default platform integer. In |
| 837 | that case, the default platform integer is used. |
| 838 | out : ndarray, optional |
| 839 | Alternative output array in which to place the result. It must |
| 840 | have the same shape and buffer length as the expected output |
| 841 | but the type will be cast if necessary. See :ref:`ufuncs-output-type` for |
| 842 | more details. |
| 843 | |
| 844 | Returns |
| 845 | ------- |
| 846 | nancumsum : ndarray. |
| 847 | A new array holding the result is returned unless `out` is |
| 848 | specified, in which it is returned. The result has the same |
| 849 | size as `a`, and the same shape as `a` if `axis` is not None |
| 850 | or `a` is a 1-d array. |
| 851 | |
| 852 | See Also |
| 853 | -------- |
| 854 | numpy.cumsum : Cumulative sum across array propagating NaNs. |
| 855 | isnan : Show which elements are NaN. |
| 856 | |
| 857 | Examples |
| 858 | -------- |
| 859 | >>> import numpy as np |
| 860 | >>> np.nancumsum(1) |
| 861 | array([1]) |
| 862 | >>> np.nancumsum([1]) |
| 863 | array([1]) |
| 864 | >>> np.nancumsum([1, np.nan]) |
| 865 | array([1., 1.]) |
| 866 | >>> a = np.array([[1, 2], [3, np.nan]]) |
| 867 | >>> np.nancumsum(a) |
| 868 | array([1., 3., 6., 6.]) |
| 869 | >>> np.nancumsum(a, axis=0) |
| 870 | array([[1., 2.], |
| 871 | [4., 2.]]) |
| 872 | >>> np.nancumsum(a, axis=1) |
| 873 | array([[1., 3.], |
| 874 | [3., 3.]]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…