code: def sparsify(
      matrix: numpy.ndarray,
      threshold: Optional[float] = None,
  ) -> scipy.sparse.spmatrix:
      """
      Sparsify a matrix.
  
      :param matrix: shape: (m, n)
          the (dense) matrix
      :param threshold:
          the absolute threshold for sparsification
  
      :return: shape: (m, n)
          a sparsified matrix
      """
      if threshold is not None:
          matrix = numpy.copy(matrix)
          matrix[matrix < threshold] = 0.0
      sparse = scipy.sparse.csr_matrix(matrix)
      sparse.eliminate_zeros()
      return sparse
  
file_path: pykeen/src/pykeen/models/baseline/utils.py
imports: from typing import Optional, Tuple
  import numpy
  import scipy.sparse
  import torch
  from sklearn.preprocessing import normalize
  from ...triples import CoreTriplesFactory
  from ...triples.leakage import jaccard_similarity_scipy, triples_factory_to_sparse_matrices
label_desc: Use image node_id 3 for calling a global function with example usage: sparsify(matrix, threshold) and returns: sparse