code: def _num_samples(x):
      """Return number of samples in array-like x."""
      message = "Expected sequence or array-like, got %s" % type(x)
      if hasattr(x, "fit") and callable(x.fit):
          # Don't get num_samples from an ensembles length!
          raise TypeError(message)
  
      if not hasattr(x, "__len__") and not hasattr(x, "shape"):
          if hasattr(x, "__array__"):
              x = np.asarray(x)
          else:
              raise TypeError(message)
  
      if hasattr(x, "shape") and x.shape is not None:
          if len(x.shape) == 0:
              raise TypeError(
                  "Singleton array %r cannot be considered a valid collection."
                  % x
              )
          # Check that shape is returning an integer or default to len
          # Dask dataframes may not return numeric shape[0] value
          if isinstance(x.shape[0], numbers.Integral):
              return x.shape[0]
  
      try:
          return len(x)
      except TypeError as type_error:
          raise TypeError(message) from type_error
  
imports: import numbers
  import operator
  import warnings
  from contextlib import suppress
  from functools import reduce, wraps
  from inspect import Parameter, isclass, signature
  import joblib
  import numpy
  import scipy.sparse
  from ..None import get_config
  from ..exceptions import DataConversionWarning, NotFittedError, PositiveSpectrumWarning
  from ..utils._array_api import _asarray_with_order, _is_numpy_namespace, get_namespace
  from ..utils.fixes import ComplexWarning
  from ._isfinite import FiniteStatus, cy_isfinite
  from .fixes import _object_dtype_isnan
label_desc: Use image node_id 9 for calling a global function with example usage: _num_samples(x) and returns: len, x