def create_connect_viewer(N, N1, imgs, count, W2):
 pv = PatchViewer((N, count), imgs.shape[1:3], is_color=(imgs.shape[3] == 3))
 for i in xrange(N):
  w = W2[:, i]
  wneg = w[(w < 0.0)]
  wpos = w[(w > 0.0)]
  w /= np.abs(w).max()
  wa = np.abs(w)
  to_sort = zip(wa, range(N1), w)
  s = sorted(to_sort)
  for j in xrange(count):
   idx = s[((N1 - j) - 1)][1]
   mag = s[((N1 - j) - 1)][2]
   if (mag > 0):
    act = (mag, 0)
   else:
    act = (0, (- mag))
   pv.add_patch(imgs[idx, ...], rescale=True, activation=act)
 return pv

def create_connect_viewer ( N , N1 , imgs , count , W2 ) : pv = PatchViewer ( ( N , count ) , imgs . shape [ 1 : 3 ] , is_color = ( imgs . shape [ 3 ] == 3 ) ) for i in xrange ( N ) : w = W2 [ : , i ] wneg = w [ ( w < 0.0 ) ] wpos = w [ ( w > 0.0 ) ] w /= np . abs ( w ) . max ( ) wa = np . abs ( w ) to_sort = zip ( wa , range ( N1 ) , w ) s = sorted ( to_sort ) for j in xrange ( count ) : idx = s [ ( ( N1 - j ) - 1 ) ] [ 1 ] mag = s [ ( ( N1 - j ) - 1 ) ] [ 2 ] if ( mag > 0 ) : act = ( mag , 0 ) else : act = ( 0 , ( - mag ) ) pv . add_patch ( imgs [ idx , ... ] , rescale = True , activation = act ) return pv
create the patch to show connections between layers .