Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么代码告诉我矢量订阅超出范围_C++ - Fatal编程技术网

C++ 为什么代码告诉我矢量订阅超出范围

C++ 为什么代码告诉我矢量订阅超出范围,c++,C++,我为一个神经网络做了一个程序,所有的东西都很好,但下面几行代码: 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 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];


            }

        }

    }
for(无符号i=0;i

执行错误向量subscribting超出范围,我正在尽最大努力,但找不到错误

您在第二个for循环中犯了错误,在第二个for循环声明中,“I”正在递增,“I”的值超过了您的向量大小

只需替换:

for (unsigned l = 0; l < Net[i].size(); i++)
应在三个位置(在**之间)替换为:

你有这个错误

for (unsigned l = 0; l < Net[i].size(); i++)
for(无符号l=0;l
应该是

for (unsigned l = 0; l < Net[i].size(); l++)
for(无符号l=0;l

使用名为
l
,使用名为
l
的变量确实不是一个好主意,对于
i
1
,即使使用上述修复程序
Net[i+1][k]。值
也会引起问题。我认为错误不是来自“i”的,因为“i”从0变为大小-1@marc对不起,当
i
等于
size()-1
,那么
i+1
等于
size()
。这是一个错误,因为大小为
n
的向量的VAID索引是
0
n-1
。我错误地表述了我的评论,“I”从未达到大小-1,因为“I”小于大小-1,而不是@marc是的,你是对的。代码被编辑了吗?我以为上面说的是
I
,不用担心,朋友。
Net[i + 1][l]



**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];
for (unsigned l = 0; l < Net[i].size(); i++)
for (unsigned l = 0; l < Net[i].size(); l++)