def safe_mask(X, mask):
 mask = np.asarray(mask)
 if np.issubdtype(mask.dtype, np.int):
  return mask
 if hasattr(X, 'toarray'):
  ind = np.arange(mask.shape[0])
  mask = ind[mask]
 return mask

def safe_mask ( X , mask ) : mask = np . asarray ( mask ) if np . issubdtype ( mask . dtype , np . int ) : return mask if hasattr ( X , 'toarray' ) : ind = np . arange ( mask . shape [ 0 ] ) mask = ind [ mask ] return mask
return a mask which is safe to use on x .