diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index 6f0dee123bcc..157b30e70964 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -921,6 +921,10 @@ NPY_NO_EXPORT void *((@type@ *)op1) = 1; continue; } + if (in1 == 1) { + *((@type@ *)op1) = 1; + continue; + } if (in2 < 0 || in1 == 0) { *((@type@ *)op1) = 0; continue; diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index f2f94d7bf3a6..759e996e31bb 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -434,6 +434,10 @@ def test_integer_power_with_zero_exponent(self): arr = np.arange(-10, 10) assert_equal(np.power(arr, 0), np.ones_like(arr)) + def test_integer_power_of_1(self): + arr = np.arange(-10, 10) + assert_equal(np.power(1, arr), np.ones_like(arr)) + class TestLog2(TestCase): def test_log2_values(self):