def display_w(w, s, r, c, fig, vmax=None, vmin=None, dataset='mnist', title='weights'):

  if dataset == 'norb':
    numvis = 4096
  else:
    numvis = w.shape[0]
  numhid = w.shape[1]
  sc = s
  sr = numvis/s
  if isinstance(w, np.ndarray):
    vh = w.T[:,:sr*sc].reshape(sr*numhid, sc)
  else:
    vh = w.asarray().T[:,:sr*sc].reshape(sr*numhid, sc)
  pvh = np.zeros((sr*r, sc*c))
  for i in range(r):
    for j in range(c):
      pvh[i*sr:(i+1)*sr , j*sc:(j+1)*sc] = vh[ (i*c+j)*sr : (i*c+j+1)*sr ,:]
  plt.figure(fig)
  plt.clf()
  plt.title(title)
  plt.imshow(pvh, cmap = plt.cm.gray, interpolation = 'nearest', vmax=vmax, vmin=vmin)
  scale = 1
  xmax = sc*c
  ymax = sr*r
  color = 'k'
  if r > 1:
    for x in range(0,c):
      plt.axvline(x=x*sc/scale, ymin=0,ymax=ymax/scale, color = color)
  if c > 1:
    for y in range(0,r):
      plt.axhline(y=y*sr/scale, xmin=0,xmax=xmax/scale, color = color)
  plt.draw()

  return pvh
dataset/ETHPy150Open nitishsrivastava/deepnet/deepnet/visualize.py/display_w/original