code: def to_numpy(X):
      
      if isinstance(X, np.ndarray):
          return X
  
      if is_pandas_ndframe(X):
          return X.values
  
      if not is_torch_data_type(X):
          raise TypeError("Cannot convert this data type to a numpy array.")
  
      if X.is_cuda:
          X = X.cpu()
  
      if X.requires_grad:
          X = X.detach()
  
      return X.numpy()
docs: Generic function to convert a pytorch tensor to numpy.
  
      Returns X when it already is a numpy array.