code: def write_matrix_ascii(file_or_fd, mat, key=None):
      """This function writes the matrix 'mat' stored as a list of lists
      in kaldi matrix text format.
      The destination can be a file or an opened file descriptor.
      If key is provided, then matrix is written to an archive with the 'key'
      as the index field.
      """
      try:
          fd = open(file_or_fd, "w")
      except TypeError:
          # 'file_or_fd' is opened file descriptor,
          fd = file_or_fd
  
      try:
          if key is not None:
              print(
                  "{0} [".format(key), file=fd
              )  # ark-files have keys (utterance-id)
          else:
              print(" [", file=fd)
  
          num_cols = 0
          for i, row in enumerate(mat):
              line = " ".join(["{0:f}".format(x) for x in row])
              if i == 0:
                  num_cols = len(row)
              elif len(row) != num_cols:
                  raise Exception(
                      "All the rows of a matrix are expected to "
                      "have the same length"
                  )
  
              if i == len(mat) - 1:
                  line += " ]"
              print(line, file=fd)
      finally:
          if fd is not file_or_fd:
              fd.close()
  
imports: from __future__ import print_function
  from __future__ import division
  import argparse
  import logging
  import math
  import os
  import subprocess
  import sys
  import threading
label_desc: Use image node_id 18 for calling a global function with example usage: write_matrix_ascii(file_or_fd, mat, key) without return types