code: def batch_dense_to_sparse(batch, dynamic_axis=""):
      """
      Helper test function that converts a batch of dense tensors into sparse
      representation that can be consumed by :func:`cntk.ops.sparse_input_numpy`.
  
      Args:
          batch (list): list of samples. If ``dynamic_axis`` is given, samples are sequences
           of tensors. Otherwise, they are simple tensors.
          dynamic_axis (str or :func:`cntk.ops.dynamic_axis` instance): the dynamic axis
  
      Returns:
          (indices, values, shape)
      """
  
      batch_indices = []
      batch_values = []
  
      shapes_in_tensor = set()
  
      for tensor in batch:
          if isinstance(tensor, list):
              tensor = np.asarray(tensor)
  
          if dynamic_axis:
              # collecting the shapes ignoring the dynamic axis
              shapes_in_tensor.add(tensor.shape[1:])
          else:
              shapes_in_tensor.add(tensor.shape)
  
          if len(shapes_in_tensor) != 1:
              raise ValueError(
                  "except for the sequence dimensions all shapes "
                  + "should be the same - instead we %s"
                  % (", ".join(str(s) for s in shapes_in_tensor))
              )
  
          t_indices = range(tensor.size)
          t_values = tensor.ravel(order="F")
          mask = t_values != 0
  
          batch_indices.append(list(np.asarray(t_indices)[mask]))
          batch_values.append(list(np.asarray(t_values)[mask]))
  
      return batch_indices, batch_values, shapes_in_tensor.pop()
  
file_path: CNTK/bindings/python/cntk/ops/tests/ops_test_utils.py
imports: import os
  import numpy
  import cntk
  from cntk.tests.test_utils import *
  from cntk.device import cpu, gpu
  from ...ops.functions import Function
  from cntk.internal import sanitize_dtype_cntk
  from cntk.internal.utils import eval
  from ..None import constant
label_desc: Use image node_id 7 for calling a global function with example usage: batch_dense_to_sparse(batch, dynamic_axis) and returns: batch_indices,  batch_values,  shapes_in_tensor