code: def _to_numpy(Z):
          
          if Z is None:
              return Z
          elif issparse(Z):
              return Z.toarray()
          elif isinstance(Z, np.ndarray):
              return Z
          elif isinstance(Z, list):
              return np.array(Z)
          elif isinstance(Z, torch.Tensor):
              return Z.cpu().numpy()
          else:
              msg = (
                  f"Expected None, list, numpy.ndarray or torch.Tensor, "
                  f"got {type(Z)} instead."
              )
              raise Exception(msg)
docs: Converts a None, list, np.ndarray, or torch.Tensor to np.ndarray;
          also handles converting sparse input to dense.