code: def to_matrix(x, dtype=np.double, copy=False):
      """
      Given some array-like X, return a numpy ndarray of the same type.
      """
      # Make sure it's array-like at all.
      if (
          not hasattr(x, "__len__")
          and not hasattr(x, "shape")
          and not hasattr(x, "__array__")
      ):
          raise TypeError("given argument is not array-like")
  
      if (
          isinstance(x, np.ndarray)
          and x.dtype == dtype
          and x.flags.c_contiguous
      ):
          if copy:  # Copy the matrix if required.
              return x.copy("C"), True
          else:
              return x, False
      elif (
          isinstance(x, np.ndarray)
          and x.dtype == dtype
          and x.flags.f_contiguous
      ):
          # A copy is always necessary here.
          return x.copy("C"), True
      else:
          if isinstance(x, pd.core.series.Series) or isinstance(
              x, pd.DataFrame
          ):
              # We can only avoid a copy if the dtype is the same and the copy flag is
              # false.  I'm actually not sure if this is possible, since in everything I
              # have found, Pandas stores with F_CONTIGUOUS not C_CONTIGUOUS.
              y = x.values
              if (
                  copy == False
                  and y.dtype == dtype
                  and y.flags.c_contiguous
              ):
                  return (
                      np.ndarray(
                          y.shape,
                          buffer=x.values,
                          dtype=dtype,
                          order="C",
                      ),
                      False,
                  )
              else:
                  # We have to make a copy or change the dtype, so just do this directly.
                  return (
                      np.array(y, dtype=dtype, order="C", copy=True),
                      True,
                  )
          else:
              return (
                  np.array(x, copy=True, dtype=dtype, order="C"),
                  True,
              )
  
imports: import numpy
  import pandas
label_desc: Use image node_id 1 for calling a global function with example usage: to_matrix(x, dtype, copy) and returns: x,  True, x,  False, x,  True, np,  True, np,  False, np,  True