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 np.full(np.shape(x), 2, dtype=np.float32)
  
      result = zeros.newton(
          f, x0_array, fprime=fp, fprime2=fpp_array, full_output=True
      )
      assert result.converged.all()
  
imports: import pytest
  from math import sqrt, exp, sin, cos
  from functools import lru_cache
  from numpy.testing import assert_warns, assert_, assert_allclose, assert_equal, assert_array_equal, suppress_warnings
  import numpy
  from numpy import finfo, power, nan, isclose
  from scipy.optimize import zeros, newton, root_scalar
  from scipy._lib._util import getfullargspec_no_self
  from scipy.optimize._tstutils import get_tests, functions, fstrings
label_desc: Use image node_id 16 for calling a global function with example usage: test_gh_9608_preserve_array_shape() and returns: unknown, unknown, int, np