diff --git a/mindspore/numpy/array_creations.py b/mindspore/numpy/array_creations.py index a2cb590508..f44911089b 100644 --- a/mindspore/numpy/array_creations.py +++ b/mindspore/numpy/array_creations.py @@ -1878,9 +1878,10 @@ def blackman(M): Examples: >>> import mindspore.numpy as np - >>> print(np.hamming(12)) - [0.08000001 0.15302339 0.34890914 0.6054648 0.841236 0.9813669 - 0.9813668 0.8412359 0.6054647 0.34890908 0.15302327 0.08000001] + >>> print(np.blackman(12)) + [-1.4901161e-08 3.2606430e-02 1.5990365e-01 4.1439798e-01 + 7.3604518e-01 9.6704674e-01 9.6704674e-01 7.3604518e-01 + 4.1439798e-01 1.5990365e-01 3.2606430e-02 -1.4901161e-08] """ if not _check_window_size(M): return ones(_max(0, M)) diff --git a/mindspore/numpy/array_ops.py b/mindspore/numpy/array_ops.py index 2dfa0e2c58..b44760e18a 100644 --- a/mindspore/numpy/array_ops.py +++ b/mindspore/numpy/array_ops.py @@ -1853,7 +1853,7 @@ def take(a, indices, axis=None, mode='clip'): mode (‘raise’, ‘wrap’, ‘clip’, optional): Specifies how out-of-bounds indices will behave. - ‘raise’ – raise an error (default); + ‘raise’ – raise an error; ‘wrap’ – wrap around; @@ -2175,7 +2175,7 @@ def choose(a, choices, mode='clip'): mode (‘raise’, ‘wrap’, ‘clip’, optional): Specifies how indices outside ``[0, n-1]`` will be treated: - ‘raise’ – raise an error (default); + ‘raise’ – raise an error; ‘wrap’ – wrap around; @@ -2420,7 +2420,7 @@ def piecewise(x, condlist, funclist, *args, **kw): >>> import mindspore.numpy as np >>> x = np.linspace(-2.5, 2.5, 6) >>> print(np.piecewise(x, [x < 0, x >= 0], [-1, 1])) - [2.5 1.5 0.5 0.5 1.5 2.5] + [-1 -1 -1 1 1 1] """ x = _to_tensor(x) choicelist = funclist diff --git a/mindspore/numpy/math_ops.py b/mindspore/numpy/math_ops.py index 7bf7c8b373..43cd1fa94a 100644 --- a/mindspore/numpy/math_ops.py +++ b/mindspore/numpy/math_ops.py @@ -2507,6 +2507,7 @@ def nanmax(a, axis=None, dtype=None, keepdims=False): ``GPU`` ``CPU`` Examples: + >>> import mindspore.numpy as np >>> a = np.array([[1, 2], [3, np.nan]]) >>> output = np.nanmax(a) >>> print(output) @@ -2554,6 +2555,7 @@ def nanmin(a, axis=None, dtype=None, keepdims=False): ``GPU`` ``CPU`` Examples: + >>> import mindspore.numpy as np >>> a = np.array([[1, 2], [3, np.nan]]) >>> output = np.nanmin(a) >>> print(output) @@ -4242,19 +4244,14 @@ def argmax(a, axis=None): ``Ascend`` ``GPU`` ``CPU`` Examples: + >>> import mindspore.numpy as np >>> a = np.arange(10, 16).reshape(2, 3) >>> print(np.argmax(a)) 5 - >>> a = np.arange(10, 16).reshape(2, 3) - >>> print(np.argmax(a), axis=0) + >>> print(np.argmax(a, axis=0)) [1 1 1] - >>> a = np.arange(10, 16).reshape(2, 3) - >>> print(np.argmax(a), axis=0) + >>> print(np.argmax(a, axis=0)) [2 2] - >>> b = np.array([0, 5, 2, 3, 4, 5]) - >>> b[1] = 5 - >>> print(np.argmax(b)) - 1 """ a = _to_tensor(a) return a.argmax(axis) @@ -4283,19 +4280,14 @@ def argmin(a, axis=None): ``Ascend`` ``GPU`` ``CPU`` Examples: + >>> import mindspore.numpy as np >>> a = np.arange(10, 16).reshape(2, 3) >>> print(np.argmin(a)) 0 - >>> a = np.arange(10, 16).reshape(2, 3) - >>> print(np.argmin(a), axis=0) + >>> print(np.argmin(a, axis=0)) [0 0 0] - >>> a = np.arange(10, 16).reshape(2, 3) - >>> print(np.argmin(a), axis=0) + >>> print(np.argmin(a, axis=0)) [0 0] - >>> b = np.array([0, 5, 2, 3, 4, 5]) - >>> b[1] = 5 - >>> print(np.argmin(b)) - 0 """ a = _to_tensor(a) return a.argmin(axis) @@ -4400,7 +4392,6 @@ def interp(x, xp, fp, left=None, right=None): >>> xp = [1, 2, 3] >>> fp = [3, 2, 0] >>> print(np.interp([0, 1, 1.5, 2.72, 3.14], xp, fp)) - >>> print(np.searchsorted([1,2,3,4,5], [-10, 10, 2, 3])) [3. 3. 2.5 0.55999994 0. ] >>> UNDEF = -99.0 >>> print(np.interp(3.14, xp, fp, right=UNDEF)) @@ -4735,7 +4726,7 @@ def histogram(a, bins=10, range=None, weights=None, density=False): # pylint: di if density: count = F.cast(count, mstype.float32) count = count/diff(bin_edges)/F.reduce_sum(count) - return count, bin_edges + return count.astype(mstype.int32), bin_edges @constexpr @@ -4874,7 +4865,7 @@ def histogramdd(sample, bins=10, range=None, weights=None, density=False): # pyl shape = _expanded_shape(ndim, dedges[i].size, i) count /= _to_tensor(dedges[i]).reshape(shape) count /= s - return count, bin_edges + return count.astype(mstype.int32), bin_edges def histogram2d(x, y, bins=10, range=None, weights=None, density=False): # pylint: disable=redefined-builtin @@ -4938,7 +4929,7 @@ def histogram2d(x, y, bins=10, range=None, weights=None, density=False): # pylin 5.33333349e+00, 6.00000000e+00])) """ count, bin_edges = histogramdd((x, y), bins=bins, range=range, weights=weights, density=density) - return count, bin_edges[0], bin_edges[1] + return count.astype(mstype.int32), bin_edges[0], bin_edges[1] def matrix_power(a, n): diff --git a/tests/st/numpy_native/test_math_ops.py b/tests/st/numpy_native/test_math_ops.py index 572997b8b0..3395ebedb2 100644 --- a/tests/st/numpy_native/test_math_ops.py +++ b/tests/st/numpy_native/test_math_ops.py @@ -2176,15 +2176,15 @@ def test_histogram(): for bins in [(1, 2, 3), [2], 1, 5, 10]: # pylint: disable=redefined-builtin for range in [None, (3, 3), (2, 20)]: - match_res(mnp.histogram, onp.histogram, x, bins=bins, range=range, error=3) - match_res(mnp.histogram, onp.histogram, x, bins=bins, range=range, density=True, error=3) + match_res(mnp.histogram, onp.histogram, x, bins=bins, range=range, error=1) + match_res(mnp.histogram, onp.histogram, x, bins=bins, range=range, density=True, error=1) mnp_res = mnp.histogram(to_tensor(x), bins=bins, range=range, weights=to_tensor(weights)) onp_res = onp.histogram(x, bins=bins, range=range, weights=weights) - match_all_arrays(mnp_res, onp_res, error=3) + match_all_arrays(mnp_res, onp_res, error=1) mnp_res = mnp.histogram(to_tensor(x), bins=bins, range=range, weights=to_tensor(weights), density=True) onp_res = onp.histogram(x, bins=bins, range=range, weights=weights, density=True) - match_all_arrays(mnp_res, onp_res, error=3) + match_all_arrays(mnp_res, onp_res, error=1) @pytest.mark.level1