code: def expand_rmf_matrix(rmf):
      
      n_chan = rmf.e_min.size
      n_energy = rmf.n_grp.size
  
      expanded = np.zeros((n_energy, n_chan))
      mtx_ofs = 0
      grp_ofs = 0
  
      for i in range(n_energy):
          for j in range(rmf.n_grp[i]):
              f = rmf.f_chan[grp_ofs]
              n = rmf.n_chan[grp_ofs]
              expanded[i,f:f+n] = rmf.matrix[mtx_ofs:mtx_ofs+n]
              mtx_ofs += n
              grp_ofs += 1
  
      return expanded
docs: Expand an RMF matrix stored in compressed form.
  
      *rmf*
        An RMF object as might be returned by ``sherpa.astro.ui.get_rmf()``.
      Returns:
        A non-sparse RMF matrix.
  
      The Response Matrix Function (RMF) of an X-ray telescope like Chandra can
      be stored in a sparse format as defined in `OGIP Calibration Memo
      CAL/GEN/92-002
      <https://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/memos/cal_gen_92_002/cal_gen_92_002.html>`_.
      For visualization and analysis purposes, it can be useful to de-sparsify
      the matrices stored in this way. This function does that, returning a
      two-dimensional Numpy array.