def nanmean(a, axis=None, dtype=None, keepdims=None): a = array_ops.array(a) if np.issubdtype(a.dtype, np.bool_) or np.issubdtype(a.dtype, np.integer): return array_ops.mean(a, axis=axis, dtype=dtype, keepdims=keepdims) nan_mask = logical_not(isnan(a)) normalizer = array_ops.sum(nan_mask, axis=axis, dtype=np.int64, keepdims=keepdims) return nansum(a, axis=axis, dtype=dtype, keepdims=keepdims) / normalizer
def run_test(arr, *args, **kwargs): axis = kwargs.pop('axis', None) for fn1 in self.array_transforms: for fn2 in self.array_transforms: arr_arg = fn1(arr) axis_arg = fn2(axis) if axis is not None else None self.match( array_ops.mean(arr_arg, axis=axis_arg, *args, **kwargs), np.mean(arr_arg, axis=axis, *args, **kwargs))
def nanmean(a, axis=None, dtype=None, keepdims=None): # pylint: disable=missing-docstring a = array_ops.array(a) if np.issubdtype(a.dtype, np.bool_) or np.issubdtype(a.dtype, np.integer): return array_ops.mean(a, axis=axis, dtype=dtype, keepdims=keepdims) nan_mask = logical_not(isnan(a)) if dtype is None: dtype = a.dtype normalizer = array_ops.sum( nan_mask, axis=axis, dtype=dtype, keepdims=keepdims) return nansum(a, axis=axis, dtype=dtype, keepdims=keepdims) / normalizer