You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the function of nansum, when all elements are nan, it returns 0. However, in some cases I want it return 'nan'. Is it possible to add an option to let user determine which value (0 or nan) to return? For example:
a=np.array([[np.nan, np.nan], [1,np.nan]])
np.nansum(a, axis=1) # returns array([0, 1])# This is what I wantnp.nansum(a, axis=1, keep_nan=True) # return array([nan, 1])
The reason that I need this is because when I process image data, I need to distinguish pixels with value 0 and value nan. "Zero" means the pixel has a meaningful value, which is 0; "nan" means the pixel has a meaningless value.
I noticed that there are alrealy some disscussions about this (#6549), i.e. whether should return 0 or nan. Since it is controversial, I suggest given users an option to determine which one they want.
The text was updated successfully, but these errors were encountered:
I am not too deep into the nan functions. From a general perspective, for sum etc. (the non-NaN versions), what would make most sense to me would be default= which would complement/replace initial= with a slightly different meaning.
default= would only be used if there are no values along the axes. It would be tricky to implement it for where=, though. On first sight such an addition seems fine, but possibly very niche.
For example mean() naturally "distinguishes" since it divides by the number of non-NaN values.
Proposed new feature or change:
For the function of
nansum
, when all elements are nan, it returns 0. However, in some cases I want it return 'nan'. Is it possible to add an option to let user determine which value (0 or nan) to return? For example:The reason that I need this is because when I process image data, I need to distinguish pixels with value 0 and value nan. "Zero" means the pixel has a meaningful value, which is 0; "nan" means the pixel has a meaningless value.
I noticed that there are alrealy some disscussions about this (#6549), i.e. whether should return 0 or nan. Since it is controversial, I suggest given users an option to determine which one they want.
The text was updated successfully, but these errors were encountered: