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

  """
  w2 = np.zeros(w.shape)
  d = w.shape[1]/3
  print w.shape
  for i in range(w.shape[0]):
    for j in range(w.shape[1]/3):
      w2[i, j] = w[i, 3*j]
      w2[i, j + d] = w[i, 3*j+1]
      w2[i, j + 2*d] = w[i, 3*j+2]
  w = w2
  """

  numhid = w.shape[0]
  size_x = s
  size_y = s    # For now.
  num_channels = w.shape[1] / (size_x*size_y)
  assert num_channels == 3
  assert w.shape[1] % size_x*size_y == 0
  if isinstance(w, np.ndarray):
    vh = w.reshape(size_x*numhid*num_channels, size_y)
  else:
    vh = w.asarray().reshape(size_x*numhid*num_channels, size_y)
  pvh = np.zeros((size_x*r, size_y*c, num_channels))
  for i in range(r):
    for j in range(c):
      for ch in range(num_channels):
        pvh[i*size_x:(i+1)*size_x, j*size_y:(j+1)*size_y, ch] = \
            vh[(num_channels*(i*c+j)+ch)*size_x:(num_channels*(i*c+j)+ch+1)*size_x,:]

  # pvh /= np.std(pvh)
  plt.figure(fig)
  plt.clf()
  plt.title(title)
  plt.imshow(pvh, vmax=vmax, vmin=vmin)
  scale = 1
  xmax = size_x*c
  ymax = size_y*r
  color = 'k'
  for x in range(0, c):
    plt.axvline(x=x*size_x/scale, ymin=0,ymax=ymax/scale, color = color)
  for y in range(0, r):
    plt.axhline(y=y*size_y/scale, xmin=0,xmax=xmax/scale, color = color)
  plt.draw()

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