下标地图对象

问题描述

我正在尝试根据检查隐藏层的权重来绘制神经网络的神经元图,以了解它们正在识别的内容。特别是,我想将每个神经元的权重绘制成对应于5×5输入的5×5网格。

为此,我将权重映射为其绝对值

abs_weights = map(abs,weights) # darkness only,depends on absolute values

,然后从中绘制出一个网格(列表列表)。

grid = [abs_weights[row:(row+5)] # turn the weights into a 5*5 grid
        for row in range(0,25,5)] # weights[0:5] ... weights [20:25]

但是,当我创建此列表列表时,我被告知'map' object is not subscriptable

import random

random.seed(0) # to get repeatable results
input_size = 25 # each input is a vector of length 25
num_hidden = 5 # well have 5 neurons in the input layer
output_size = 10 # we need 10 outputs for each input

# each hidden neuron has one weight per input,plus a bis weight
hidden_layer = [[random.random() for __ in range(input_size + 1)] 
                for __ in range(num_hidden)]

# each output neuron has one weight per hidden neuron,plus a biais weight
output_layer = [[random.random() for __ in range(num_hidden + 1)]
               for __ in range(output_size)]

# the network starts out with random weights 
network = [hidden_layer,output_layer]

import matplotlib
weights = network[0][0] # first neuron in hidden layer
abs_weights = map(abs,depends on absolute values

grid = [abs_weights[row:(row+5)] # turn the weights into a 5*5 grid
        for row in range(0,5)] # weights[0:5] ... weights [20:25]

ax = plt.gca() # to use hatching we will need the axis

ax.imshow(grid,# here same as plt.imshow
          cmap = matplotlib.cm.binary,# use white-black color scale
          interpolation = None)  # plot blocks as blocks

def patch(x,y,hatch,color):
    pass

但这给了我

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-c2d051d93ba5> in <module>
      4 
      5 grid = [abs_weights[row:(row+5)] # turn the weights into a 5*5 grid
----> 6         for row in range(0,5)] # weights[0:5] ... weights [20:25]
      7 
      8 ax = plt.gca() # to use hatching we will need the axis

<ipython-input-13-c2d051d93ba5> in <listcomp>(.0)
      4 
      5 grid = [abs_weights[row:(row+5)] # turn the weights into a 5*5 grid
----> 6         for row in range(0,5)] # weights[0:5] ... weights [20:25]
      7 
      8 ax = plt.gca() # to use hatching we will need the axis

TypeError: 'map' object is not subscriptable

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...