code: def test_gh_9608_preserve_array_shape():
      """
      Test that shape is preserved for array inputs even if fprime or fprime2 is
      scalar
      """
  
      def f(x):
          return x**2
  
      def fp(x):
          return 2 * x
  
      def fpp(x):
          return 2
  
      x0 = np.array([-2], dtype=np.float32)
      rt, r = newton(f, x0, fprime=fp, fprime2=fpp, full_output=True)
      assert r.converged
  
      x0_array = np.array([-2, -3], dtype=np.float32)
      # This next invocation should fail
      with pytest.raises(IndexError):
          result = zeros.newton(
              f, x0_array, fprime=fp, fprime2=fpp, full_output=True
          )
  
      def fpp_array(x):
          return 2 * np.ones(np.shape(x), dtype=np.float32)
  
      result = zeros.newton(
          f, x0_array, fprime=fp, fprime2=fpp_array, full_output=True
      )
      assert result.converged.all()
  
imports: from __future__ import division, print_function, absolute_import
  import pytest
  from math import sqrt, exp, sin, cos
  from numpy.testing import assert_warns, assert_, assert_allclose, assert_equal, assert_array_equal
  import numpy
  from numpy import finfo, power, nan, isclose
  from scipy.optimize import zeros, newton, root_scalar
  from scipy._lib._util import getargspec_no_self
  from scipy.optimize._tstutils import get_tests, functions, fstrings
  from scipy._lib._numpy_compat import suppress_warnings
label_desc: Use image node_id 15 for calling a global function with example usage: test_gh_9608_preserve_array_shape() and returns: unknown, unknown, int, unknown