将1D矢量分配/复制到2D矢量

时间:2016-04-13 21:16:10

标签: c++ 2d-vector

我已经从2D矢量中的文本文件中加载了数据。我正在逐列提取数据,在每列中找到min,max,然后对其进行标准化。标准化数据存储在单独的临时向量中,请记住我从列中提取数据因此它应该返回到列。 我需要从标准化的单个临时向量重建原始的2D向量。

 vector <vector<double> >loadedData;
 vector <double> normal;
 vector <double> temp;
 vector <vector <double> >normalDataFrom1D;
 normalDataFrom1D.resize(rows, vector<double>(cols,0.0));

 loadedData = net.loadData(file);
 int cols = net.no_of_cols("../sampleData.txt");
 int rows = net.no_of_rows("../sampleData.txt");

    for(int i=0;i<cols;i++){
      min = net.min_1d(i);
      max = net.max_1d(i);
      cout<<"Min val in Col ["<<i<<"] data :"<<min<<endl;
      cout<<"Max val in Col ["<<i<<"] data :"<<max<<endl;
      normal = net.extract_1d(i);
      temp = net.normalizeData_1d(normal, min, max);  

      for(int r=0;r<normalDataFrom1D.size();r++){
        for(int c=0;c<normalDataFrom1D[r].size();c++){
          normalDataFrom1D[c][r] = temp;
        }
      }
    }
//Printing Data...
    for(int r=0;r<normalDataFrom1D.size();r++){
      for(int c=0;c<normalDataFrom1D[r].size();c++){
        cout<<"Data in normalDataFrom1D["<<r<<"]["<<c<<"] = "<<normalDataFrom1D[r][c]<<endl;
      }
    }

error: cannot convert ‘std::vector<double>’ to ‘double’ in assignment
           normalDataFrom1D[c][r] = temp;

如果我尝试:

temp[i].push_back(net.normalizeData_1d(normal, min, max));

它说:

error: request for member ‘push_back’ in ‘temp.std::vector<_Tp, _Alloc>::operator[]<double, std::allocator<double> >(((std::vector<double>::size_type)i))’, which is of non-class type ‘double’
       temp[i].push_back(net.normalizeData_1d(normal, min, max));

0 个答案:

没有答案