Neural network 索引数组无法与形状(103,)(103,10)一起广播
我的代码如下Neural network 索引数组无法与形状(103,)(103,10)一起广播,neural-network,ipython,softmax,Neural Network,Ipython,Softmax,我的代码如下 AL = AL.T print("AL = " + str(AL)) print("shape AL =" +str(AL.shape)) AL = [[ 0.00060828 0.00062134 0.00103428 ..., 0.00177817 0.00153976 0.00220757] [ 0.00057424 0.00059807 0.00094907 ..., 0.00181722 0.00163071 0.0017858 ] [
AL = AL.T
print("AL = " + str(AL))
print("shape AL =" +str(AL.shape))
AL = [[ 0.00060828 0.00062134 0.00103428 ..., 0.00177817 0.00153976
0.00220757]
[ 0.00057424 0.00059807 0.00094907 ..., 0.00181722 0.00163071
0.0017858 ]
[ 0.00066254 0.00051859 0.00095111 ..., 0.00170046 0.00162012
0.00231112]
...,
[ 0.00064599 0.00055204 0.00100892 ..., 0.0015652 0.00140016
0.0020871 ]
[ 0.0006461 0.00055202 0.00100921 ..., 0.00156518 0.00140028
0.00208662]
[ 0.00064608 0.00055209 0.00100905 ..., 0.00156585 0.00140004
0.00208697]]
shape AL =(103, 10)
对于Y,我有:
Y =[[0 0 0 ..., 0 0 0]
[1 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
...,
[0 1 0 ..., 0 0 0]
[0 0 1 ..., 0 0 0]
[0 0 0 ..., 0 0 0]]
shape Y = (103, 10)
m=103
然后我计算log_似然,如下所示:
log_likelihood = -np.log(AL[range(m),(Y)])
我有一个输出错误:
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (103,) (103,10)
我不明白,因为两个维度都是(103,10)
103代表我的示例,10代表我的类。
通过计算对数似然值,我是否做错了什么?m代表什么?当然,
range(m)=range(103)
的形状是(103,)并且不能用二维(103,10)张量进行广播。也许你需要-np.log(AL[range(m)],(Y))
@JoshFriedlander m代表我的示例数量(so 103)。我想它一定只是一个索引。所以Y的形状是(103,10)。那我怎么才能让我的日志工作呢?我想保持Y的维数(它是我的一个热向量)。我想对我的例子进行重覆,所以在我的例子中是103…只是为了确定,你在试图根据AL中的概率,为每一行找到最可能的Y标签?如果是这样,请尝试np.argsort
我试图计算的是在AL中找到的最高概率的每个训练示例的最小成本。