首先,这是我的代码:
"""Softmax."""
scores = [3.0, 1.0, 0.2]
import numpy as np
def softmax(x):
"""Compute softmax values for each sets of scores in x."""
num = np.exp(x)
score_len = len(x)
y = [0] * score_len
for index in range(1,score_len):
y[index] = (num[index])/(sum(num))
return y
print(softmax(scores))
# Plot softmax curves
import matplotlib.pyplot as plt
x = np.arange(-2.0, 6.0, 0.1)
scores = np.vstack([x, np.ones_like(x), 0.2 * np.ones_like(x)])
plt.plot(x, softmax(scores).T, linewidth=2)
plt.show()
现在看这个问题,我可以说 T 是我列表的转置。但是,我似乎得到了错误:
AttributeError:“列表”对象没有属性“T”
我不明白这里发生了什么。我对整个情况的理解是错误的吗?我正在尝试通过谷歌深度学习课程,我认为我可以通过实现程序来使用 Python,但我可能错了。我目前知道很多其他语言,如 C 和 Java,但新语法总是让我感到困惑。