python3.8.8运行遇到问题
问题描述:
代码:
for cnt, x in enumerate(data):
# getting the winner
w = som.winner(x)
# place a marker on the winning position for the sample xx
wx, wy = som.convert_map_to_euclidean(w)
wy = wy * np.sqrt(3) / 2
plt.plot(wx, wy,
markers[t[cnt]-1],
markerfacecolor='None',
markeredgecolor=colors[t[cnt]-1],
markersize=12,
markeredgewidth=2)
xrange = np.arange(weights.shape[0])
yrange = np.arange(weights.shape[1])
plt.xticks(xrange-.5, xrange)
plt.yticks(yrange * np.sqrt(3) / 2, yrange)
在markers[t[cnt]-1]这一行报错,不知道该如何解决。
Traceback (most recent call last):
File "naqu.py", line 67, in <module>
markers[t[cnt]-1],
TypeError: list indices must be integers or slices, not numpy.float64
答
原因: markers生成的是numpy数组,不是List,需要先转换为list才能使用里面的元素做为index
答
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632