def params2stack(params, net_config):
 depth = len(net_config['layer_sizes'])
 stack = [dict() for i in range(depth)]
 prev_layer_size = net_config['input_size']
 current_pos = 0
 for i in range(depth):
  wlen = (prev_layer_size * net_config['layer_sizes'][i])
  stack[i]['w'] = params[current_pos:(current_pos + wlen)].reshape(net_config['layer_sizes'][i], prev_layer_size)
  current_pos = (current_pos + wlen)
  blen = net_config['layer_sizes'][i]
  stack[i]['b'] = params[current_pos:(current_pos + blen)]
  current_pos = (current_pos + blen)
  prev_layer_size = net_config['layer_sizes'][i]
 return stack

def params2stack ( params , net_config ) : depth = len ( net_config [ 'layer_sizes' ] ) stack = [ dict ( ) for i in range ( depth ) ] prev_layer_size = net_config [ 'input_size' ] current_pos = 0 for i in range ( depth ) : wlen = ( prev_layer_size * net_config [ 'layer_sizes' ] [ i ] ) stack [ i ] [ 'w' ] = params [ current_pos : ( current_pos + wlen ) ] . reshape ( net_config [ 'layer_sizes' ] [ i ] , prev_layer_size ) current_pos = ( current_pos + wlen ) blen = net_config [ 'layer_sizes' ] [ i ] stack [ i ] [ 'b' ] = params [ current_pos : ( current_pos + blen ) ] current_pos = ( current_pos + blen ) prev_layer_size = net_config [ 'layer_sizes' ] [ i ] return stack
converts a flattened parameter vector into a nice "stack" structure for us to work with .