class_docstr: Find closest anchors using :mod:`scipy.sparse`.
class_docstr_tok: ["Find","closest","anchors","using",":","mod",":","`","scipy.sparse","`","."]
docstr: Select $k$ anchors from the given pools.
  
  :param pool: shape: (n, a)
      the anchor candidates for each node (a binary array)
  :param k:
      the number of candidates to select
  
  :return: shape: (n, k)
      the selected anchors. May contain -1 if there is an insufficient number of  candidates
docstr_tok: ["Select","$","k","$","anchors","from","the","given","pools",".",":","param","pool",":","shape",":","(","n",",","a",")","the","anchor","candidates","for","each","node","(","a","binary","array",")",":","param","k",":","the","number","of","candidates","to","select",":","return",":","shape",":","(","n",",","k",")","the","selected","anchors",".","May","contain","-1","if","there","is","an","insufficient","number","of","candidates"]
code: def select(
      pool: numpy.ndarray,
      k: int,
  ) -> numpy.ndarray:
      """
      Select $k$ anchors from the given pools.
  
      :param pool: shape: (n, a)
          the anchor candidates for each node (a binary array)
      :param k:
          the number of candidates to select
  
      :return: shape: (n, k)
          the selected anchors. May contain -1 if there is an insufficient number of  candidates
      """
      tokens = numpy.full(
          shape=(pool.shape[0], k), fill_value=-1, dtype=int
      )
      generator = numpy.random.default_rng()
      # TODO: can we replace this loop with something vectorized?
      for i, row in enumerate(pool):
          (this_pool,) = row.nonzero()
          chosen = generator.choice(
              a=this_pool,
              size=min(k, this_pool.size),
              replace=False,
              shuffle=False,
          )
          tokens[i, : len(chosen)] = chosen
      return tokens
  
imports: import logging
  from abc import ABC, abstractmethod
  from typing import Iterable, Optional
  import numpy
  import scipy.sparse
  import torch
  from class_resolver import ClassResolver, OptionalKwargs
  from torch_ppr import page_rank
  from torch_ppr.utils import edge_index_to_sparse_matrix, prepare_page_rank_adjacency, prepare_x0
  from tqdm.auto import tqdm
  from .utils import ensure_num_entities
  from ...typing import DeviceHint
  from ...utils import ExtraReprMixin, format_relative_comparison, resolve_device
label_desc: Use image node_id 5 for calling the ScipySparseAnchorSearcher obj's underlying member method code with example usage: obj.select(pool, k) and returns: tokens