我为神经元网络编写了一个程序,一切正常,但这些代码行:
for (unsigned i = 0; i < Net.size() - 1; i++)
{
//Net is a vector of Layers, Layers are a vector of neurons, and Neurons are a Vector of weights and a double "values", the weights are also doubles
for (unsigned l = 0; l < Net[i].size(); i++)
{
for (unsigned k = 0; k < Net[i][l].weights.size(); k++)
{
Net[i + 1][k].value = sigmoid(Net[i + 1][k].value);
Net[i+1][k].value += Net[i][l].value* Net[i][l].weights[k];
}
}
}
执行错误Vector subscribting out of range,我尽力了,但找不到错误
最佳答案
你有这个错误
for (unsigned l = 0; l < Net[i].size(); i++)
应该是
for (unsigned l = 0; l < Net[i].size(); l++)
使用名为 l
的变量确实不是一个好主意, 很容易误认为 i
或 1
.
关于c++ - 为什么代码告诉我 vector 订阅超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56882920/