code: def cast_to_ndarray(arr, /, *, as_any=True, dtype=None, copy=False):
      """Cast array to a NumPy ndarray.
  
      Parameters
      ----------
      arr : array_like
          Array to cast.
  
      as_any : bool, default: True
          Allow subclasses of ``np.ndarray`` to pass through without
          making a copy.
  
      dtype : dtype_like
          The data-type of the returned array.
  
      copy : bool, default: False
          If ``True``, a copy of the array is returned. A copy is always
          returned if the array:
  
              * is a nested sequence
              * is a subclass of ``np.ndarray`` and ``as_any`` is ``False``.
  
      Raises
      ------
      ValueError
          If input cannot be cast as a NumPy ndarray.
  
      Returns
      -------
      np.ndarray
          NumPy ndarray.
  
      """
      if (
          as_any
          and not copy
          and dtype is None
          and isinstance(arr, np.ndarray)
      ):
          return arr
      try:
          if as_any:
              out = np.asanyarray(arr, dtype=dtype)
              if copy:
                  out = out.copy()
          else:
              out = np.array(arr, dtype=dtype, copy=copy)
          if out.dtype.name == "object":
              # NumPy will normally raise ValueError automatically for
              # object arrays, but on some systems it will not, so raise
              # error manually
              raise ValueError
      except (ValueError, np.VisibleDeprecationWarning) as e:
          raise ValueError(
              f"Input cannot be cast as {np.ndarray}."
          ) from e
      return out
  
imports: import collections.abc
  import enum
  from itertools import product
  from typing import Optional, Tuple, Union
  import numpy
  import pyvista
  from pyvista.core import _vtk_core
  from pyvista.core._typing_core import Matrix, NumpyArray, TransformLike, Vector
  from pyvista.core.errors import AmbiguousDataError, MissingDataError
label_desc: Use image node_id 26 for calling a global function with example usage: cast_to_ndarray() and returns: out, arr