예제 #1
0
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
예제 #2
0
 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))
예제 #3
0
파일: math_ops.py 프로젝트: victorustc/trax
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