code: def return_dat(self, chan, begsam, endsam):
          
          dat_begsam = max(begsam, 0)
          dat_endsam = min(endsam, self.n_samples)
          dur = dat_endsam - dat_begsam
  
          dtype_onlychan = dtype({k: v for k, v in self.dtype.fields.items() if v[0].kind != 'S'})
  
          # make sure we read some data at least, otherwise segfault
          if dat_begsam < self.n_samples and dat_endsam > 0:
  
              with self.filename.open('rb') as f:
                  f.seek(self.header_len, SEEK_SET)  # skip header
  
                  f.seek(self.dtype.itemsize * dat_begsam, SEEK_CUR)
                  dat = fromfile(f, dtype=self.dtype, count=dur)
  
              dat = ndarray(dat.shape, dtype_onlychan, dat, 0, dat.strides).view((dtype_onlychan[0], len(dtype_onlychan.names))).T
  
          else:
              n_chan = len(dtype_onlychan.names)
              dat = empty((n_chan, 0))
  
          if begsam < 0:
  
              pad = empty((dat.shape[0], 0 - begsam))
              pad.fill(NaN)
              dat = c_[pad, dat]
  
          if endsam >= self.n_samples:
  
              pad = empty((dat.shape[0], endsam - self.n_samples))
              pad.fill(NaN)
              dat = c_[dat, pad]
  
          return dat[chan, :] * self.gain[chan][:, None]
docs: Return the data as 2D numpy.ndarray.
  
          Parameters
          ----------
          chan : int or list
              index (indices) of the channels to read
          begsam : int
              index of the first sample
          endsam : int
              index of the last sample
  
          Returns
          -------
          numpy.ndarray
              A 2d matrix, with dimension chan X samples