擅长:python、mysql、java
<p>也许是这样:</p>
<pre><code>import numpy as np
error = np.array([[0.32783139, 0.29204386, 0.0572163 , 0.96162543, 0.8343454 ],
[0.67308787, 0.27715222, 0.11738748, 0.091061 , 0.51806117]])
label= np.array([[0, 0, 0, 1, 0 ],
[0, 1, 0, 0, 0]])
def f(error, label):
per_ts_loss=0
t=np.zeros(error.shape)
argma=np.argmax(label, axis=1)
t[[i for i in range(error.shape[0])],argma]=-1
print(t)
error+=t
per_ts_loss += error[[i for i in range(error.shape[0])],argma]
f(error, label)
</code></pre>
<p>输出:</p>
<pre><code>[[ 0. 0. 0. -1. 0.]
[ 0. -1. 0. 0. 0.]]
</code></pre>