def sort_layer2(W2):
 print('Sorting so largest-norm layer 2 weights are plotted at the top')
 norms = np.square(W2).sum(axis=0)
 idxs = [elem[1] for elem in sorted(zip((- norms), range(norms.shape[0])))]
 new = W2.copy()
 for i in xrange(len(idxs)):
  new[:, i] = W2[:, idxs[i]]
 W2 = new
 return new

def sort_layer2 ( W2 ) : print ( 'Sorting so largest-norm layer 2 weights are plotted at the top' ) norms = np . square ( W2 ) . sum ( axis = 0 ) idxs = [ elem [ 1 ] for elem in sorted ( zip ( ( - norms ) , range ( norms . shape [ 0 ] ) ) ) ] new = W2 . copy ( ) for i in xrange ( len ( idxs ) ) : new [ : , i ] = W2 [ : , idxs [ i ] ] W2 = new return new
sort weights of the a layer .