code: def _write_array_header(fp, d, version=None):
      """Write the header for an array and returns the version used
  
      Parameters
      ----------
      fp : filelike object
      d : dict
          This has the appropriate entries for writing its string representation
          to the header of the file.
      version: tuple or None
          None means use oldest that works
          explicit version will raise a ValueError if the format does not
          allow saving this data.  Default: None
      Returns
      -------
      version : tuple of int
          the file version which needs to be used to store the data
      """
      import struct
  
      header = ["{"]
      for key, value in sorted(d.items()):
          # Need to use repr here, since we eval these when reading
          header.append("'%s': %s, " % (key, repr(value)))
      header.append("}")
      header = "".join(header)
      header = asbytes(_filter_header(header))
  
      hlen = len(header) + 1  # 1 for newline
      padlen_v1 = ARRAY_ALIGN - (
          (MAGIC_LEN + struct.calcsize("<H") + hlen) % ARRAY_ALIGN
      )
      padlen_v2 = ARRAY_ALIGN - (
          (MAGIC_LEN + struct.calcsize("<I") + hlen) % ARRAY_ALIGN
      )
  
      # Which version(s) we write depends on the total header size; v1 has a max of 65535
      if hlen + padlen_v1 < 2**16 and version in (None, (1, 0)):
          version = (1, 0)
          header_prefix = magic(1, 0) + struct.pack(
              "<H", hlen + padlen_v1
          )
          topad = padlen_v1
      elif hlen + padlen_v2 < 2**32 and version in (None, (2, 0)):
          version = (2, 0)
          header_prefix = magic(2, 0) + struct.pack(
              "<I", hlen + padlen_v2
          )
          topad = padlen_v2
      else:
          msg = "Header length %s too big for version=%s"
          msg %= (hlen, version)
          raise ValueError(msg)
  
      # Pad the header with spaces and a final newline such that the magic
      # string, the header-length short and the header are aligned on a
      # ARRAY_ALIGN byte boundary.  This supports memory mapping of dtypes
      # aligned up to ARRAY_ALIGN on systems like Linux where mmap()
      # offset must be page-aligned (i.e. the beginning of the file).
      header = header + b" " * topad + b"\n"
  
      fp.write(header_prefix)
      fp.write(header)
      return version
  
imports: from __future__ import division, absolute_import, print_function
  import numpy
  import sys
  import io
  import warnings
  from numpy.lib.utils import safe_eval
  from numpy.compat import asbytes, asstr, isfileobj, long, os_fspath
  from numpy.core.numeric import pickle
label_desc: Use image node_id 7 for calling a global function with example usage: _write_array_header(fp, d, version) and returns: version