code: def _get_finite_row_indices(matrix):
      """
      Returns the indices of the purely finite rows of a
      sparse matrix or dense ndarray
      """
      if issparse(matrix):
          row_indices = np.array(
              [
                  i
                  for i, row in enumerate(matrix.tolil().data)
                  if np.all(np.isfinite(row))
              ]
          )
      else:
          (row_indices,) = np.isfinite(matrix.sum(axis=1)).nonzero()
      return row_indices
  
imports: from numbers import Integral, Real
  from warnings import warn
  import numpy
  from scipy.sparse import csgraph, issparse
  from ...base import BaseEstimator, ClusterMixin, _fit_context
  from ...metrics import pairwise_distances
  from ...metrics._dist_metrics import DistanceMetric
  from ...neighbors import BallTree, KDTree, NearestNeighbors
  from ...utils._param_validation import Interval, StrOptions
  from ...utils.validation import _allclose_dense_sparse, _assert_all_finite
  from ._linkage import MST_edge_dtype, make_single_linkage, mst_from_data_matrix, mst_from_mutual_reachability
  from ._reachability import mutual_reachability_graph
  from ._tree import HIERARCHY_dtype, labelling_at_cut, tree_to_labels
label_desc: Use image node_id 6 for calling a global function with example usage: _get_finite_row_indices(matrix) and returns: row_indices