code: def mergemat(args):
      
      p = OptionParser(mergemat.__doc__)
      p.set_outfile(outfile="out")
      opts, args = p.parse_args(args)
  
      if len(args) < 1:
          sys.exit(not p.print_help())
  
      npyfiles = args
      A = np.load(npyfiles[0])
      logging.debug("Load `{}`: matrix of shape {}:; sum={}"
                    .format(npyfiles[0], A.shape, A.sum()))
      for npyfile in npyfiles[1:]:
          B = np.load(npyfile)
          A += B
          logging.debug("Load `{}`: sum={}"
                        .format(npyfiles[0], A.sum()))
  
      pf = opts.outfile
      np.save(pf, A)
      logging.debug("Combined {} files into `{}.npy`".format(len(npyfiles), pf))
docs: %prog mergemat *.npy
  
      Combine counts from multiple .npy data files.