!12971 [Numpy-Native] fix typeerror of np.average, np.std, np.var

From: @wangrao124
Reviewed-by: @liangchenghui,@guoqi1024
Signed-off-by: @liangchenghui
pull/12971/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit c61f1fff2c

@ -1058,6 +1058,8 @@ def std(x, axis=None, ddof=0, keepdims=False):
if not isinstance(ddof, int): if not isinstance(ddof, int):
_raise_type_error("integer argument expected, but got ", ddof) _raise_type_error("integer argument expected, but got ", ddof)
if not isinstance(keepdims, int):
_raise_type_error("integer argument expected, but got ", keepdims)
if axis is None: if axis is None:
axis = () axis = ()
else: else:
@ -1179,7 +1181,7 @@ def average(x, axis=None, weights=None, returned=False):
axis (Union[None, int, tuple(int)]): Axis along which to average `x`. Default: `None`. axis (Union[None, int, tuple(int)]): Axis along which to average `x`. Default: `None`.
If the axis is `None`, it will average over all of the elements of the tensor `x`. If the axis is `None`, it will average over all of the elements of the tensor `x`.
If the axis is negative, it counts from the last to the first axis. If the axis is negative, it counts from the last to the first axis.
weights (Tensor): Weights associated with the values in `x`. Default: `None`. weights (Union[None, Tensor]): Weights associated with the values in `x`. Default: `None`.
If `weights` is `None`, all the data in `x` are assumed to have a weight equal to one. If `weights` is `None`, all the data in `x` are assumed to have a weight equal to one.
If `weights` is 1-D tensor, the length must be the same as the given axis. If `weights` is 1-D tensor, the length must be the same as the given axis.
Otherwise, `weights` should have the same shape as `x`. Otherwise, `weights` should have the same shape as `x`.
@ -1201,6 +1203,7 @@ def average(x, axis=None, weights=None, returned=False):
(Tensor(shape=[2], dtype=Float32, value= [ 2.50000000e+00, 3.33333325e+00]), (Tensor(shape=[2], dtype=Float32, value= [ 2.50000000e+00, 3.33333325e+00]),
Tensor(shape=[2], dtype=Float32, value= [ 4.00000000e+00, 6.00000000e+00])) Tensor(shape=[2], dtype=Float32, value= [ 4.00000000e+00, 6.00000000e+00]))
""" """
_check_input_tensor(x)
if axis is None: if axis is None:
axis = () axis = ()
else: else:
@ -1225,6 +1228,7 @@ def average(x, axis=None, weights=None, returned=False):
fill_value *= x.shape[ax] fill_value *= x.shape[ax]
sum_of_weights = full_like(x_avg, fill_value, F.dtype(x)) sum_of_weights = full_like(x_avg, fill_value, F.dtype(x))
else: else:
_check_input_tensor(weights)
if x.shape == weights.shape: if x.shape == weights.shape:
x_avg, sum_of_weights = comput_avg(x, axis, weights) x_avg, sum_of_weights = comput_avg(x, axis, weights)
elif F.rank(weights) == 1: elif F.rank(weights) == 1:

Loading…
Cancel
Save