diff --git a/python/mxnet/numpy/multiarray.py b/python/mxnet/numpy/multiarray.py index d59eddc3d139..11ea0858cccd 100644 --- a/python/mxnet/numpy/multiarray.py +++ b/python/mxnet/numpy/multiarray.py @@ -1170,11 +1170,15 @@ def nanprod(self, *args, **kwargs): def mean(self, axis=None, dtype=None, out=None, keepdims=False): # pylint: disable=arguments-differ """Returns the average of the array elements along given axis.""" - raise NotImplementedError + return mean(self, axis=axis, dtype=dtype, out=out, keepdims=keepdims) def std(self, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint: disable=arguments-differ """Returns the standard deviation of the array elements along given axis.""" - return _mx_np_op.std(self, axis=axis, dtype=dtype, ddof=ddof, keepdims=keepdims, out=out) + return std(self, axis=axis, dtype=dtype, ddof=ddof, keepdims=keepdims, out=out) + + def var(self, axis=None, dtype=None, out=None, ddof=0, keepdims=None): # pylint: disable=arguments-differ + """Returns the variance of the array elements, along given axis.""" + return var(self, axis=axis, dtype=dtype, out=out, ddof=ddof, keepdims=keepdims) def cumsum(self, axis=None, dtype=None, out=None): """Return the cumulative sum of the elements along the given axis.""" diff --git a/python/mxnet/symbol/numpy/_symbol.py b/python/mxnet/symbol/numpy/_symbol.py index e752c5801bb8..38e9086bb281 100644 --- a/python/mxnet/symbol/numpy/_symbol.py +++ b/python/mxnet/symbol/numpy/_symbol.py @@ -530,12 +530,16 @@ def nanprod(self, *args, **kwargs): raise AttributeError('_Symbol object has no attribute nanprod') def mean(self, axis=None, dtype=None, out=None, keepdims=False): # pylint: disable=arguments-differ - """Convenience fluent method for :py:func:`mean`. + """Returns the average of the array elements along given axis.""" + return mean(self, axis=axis, dtype=dtype, out=out, keepdims=keepdims) - The arguments are the same as for :py:func:`mean`, with - this array as data. - """ - return _npi.mean(self, axis=axis, dtype=dtype, keepdims=keepdims, out=out) + def std(self, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint: disable=arguments-differ,too-many-arguments + """Returns the standard deviation of the array elements along given axis.""" + return std(self, axis=axis, dtype=dtype, ddof=ddof, keepdims=keepdims, out=out) + + def var(self, axis=None, dtype=None, out=None, ddof=0, keepdims=None): # pylint: disable=arguments-differ,too-many-arguments + """Returns the variance of the array elements, along given axis.""" + return var(self, axis=axis, dtype=dtype, out=out, ddof=ddof, keepdims=keepdims) def cumsum(self, axis=None, dtype=None, out=None): """Return the cumulative sum of the elements along the given axis.""" diff --git a/tests/python/unittest/test_numpy_op.py b/tests/python/unittest/test_numpy_op.py index c137b30f89c3..51aa9054451c 100644 --- a/tests/python/unittest/test_numpy_op.py +++ b/tests/python/unittest/test_numpy_op.py @@ -401,7 +401,7 @@ def __init__(self, axis=None, dtype=None, keepdims=False): self._keepdims = keepdims def hybrid_forward(self, F, a, *args, **kwargs): - return F.np.mean(a, axis=self._axis, dtype=self._dtype, keepdims=self._keepdims) + return a.mean(axis=self._axis, dtype=self._dtype, keepdims=self._keepdims) def is_int(dtype): return 'int' in dtype @@ -467,7 +467,7 @@ def __init__(self, name, axis=None, dtype=None, keepdims=False, ddof=0): self._ddof = ddof def hybrid_forward(self, F, a, *args, **kwargs): - return getattr(F.np, self._name)(a, axis=self._axis, dtype=self._dtype, keepdims=self._keepdims, ddof=self._ddof) + return getattr(a, self._name)(axis=self._axis, dtype=self._dtype, keepdims=self._keepdims, ddof=self._ddof) def is_int(dtype): return 'int' in dtype