我正在尝试使用for
循环来定义列表:
import numpy as np
# 2 input neurons , next 3 hidden , 5 hidden , 2 output neurons
layer_sizes = { 2,3,5,2 }
# for matrix shapes 3,2 5,3 and 2,5
weight_shapes = [{a,b} for a,b in zip(layer_sizes[1:],layer_sizes[:-1])]
#weight_shapes = [ {3,2},{5,3},{2,5}]
weights = [np.zeros(s) for s in weight_shapes]
print(weight_shapes)
print(weights)
但是我一直收到此错误:
Traceback (most recent call last):
File "C:\Users\USER\NNe2.py", line 5, in <module>
weight_shapes = [{a,b} for a,b in zip(layer_sizes[1:],layer_sizes[:-1])]
TypeError: 'set' object is not subscriptable
我希望打印语句能够提供列表的内容。