code: def write_binary_matrix(filename, array):
      """Writes array as a binary formatted matrix to the file.
  
      The file format is described on the data set page:
      https://cs.nyu.edu/~ylclab/data/norb-v1.0-small/
  
      Args:
        filename: String with path to the file.
        array: Numpy array that should be written to the file.
      """
      with tf.io.gfile.GFile(filename, "wb") as f:
          # All data is stored in little-endian byte order.
          int32_dtype = np.dtype("int32").newbyteorder("<")
  
          # The first 4 bytes specify the data type.
          if array.dtype.str == "<i4":
              # Magic code for little-endian int32.
              f.write(
                  np.asarray(507333716, dtype=int32_dtype).tobytes()
              )
          elif array.dtype.str == "|u1":
              # Magic code for uint8.
              f.write(
                  np.asarray(507333717, dtype=int32_dtype).tobytes()
              )
          else:
              raise ValueError(
                  "Array data type %r not supported." % array.dtype.str
              )
  
          # Next, we specify the number of dimensions of the array to be stored as a
          # 32 bit integer.
          f.write(np.asarray(array.ndim, int32_dtype).tobytes())
  
          # The shape of the array is saved as 32-bit integers. If there are less than
          # 3 dimensions, the shape is padded with ones.
          shape = list(array.shape) + [1] * max(0, 3 - array.ndim)
          f.write(np.asarray(shape, int32_dtype).tobytes())
  
          # Finally, the data is written as a C-contiguous matrix. There is no need to
          # check for the byte order as we checked for this when writing the magic
          # code.
          f.write(np.ascontiguousarray(array).tobytes())
  
file_path: datasets/tensorflow_datasets/testing/fake_data_generation/smallnorb.py
imports: import os
  from absl import app
  from absl import flags
  import numpy
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  from tensorflow_datasets.testing import test_utils
label_desc: Use image node_id 1 for calling a global function with example usage: write_binary_matrix(filename, array) without return types