code: def _sparsify(x, thresh=0.5, index_dtype=np.int64):
      x[x < thresh] = 0
  
      non_zero = np.where(x)
      x_indices = np.vstack(non_zero).astype(index_dtype).T
      x_values = x[non_zero]
      x_shape = x.shape
  
      return sparse_tensor.SparseTensor(
          indices=x_indices, values=x_values, dense_shape=x_shape
      ), len(x_values)
  
imports: import timeit
  import numpy
  from tensorflow.python.client import session
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors_impl
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import gradient_checker
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import sparse_ops
  import tensorflow.python.ops.sparse_grad
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling a global function with example usage: _sparsify(x, thresh, index_dtype) and returns: sparse_tensor,  len