私はdlibで定義されたcolumeベクトルを持っています。どうすればstd :: vectorに変換できますか?dlibの行列をstd :: vectorに変換する方法
typedef dlib::matrix<double,0,1> column_vector;
column_vector starting_point(4);
starting_point = 1,2,3,4;
std::vector x = ??
おかげ
私はdlibで定義されたcolumeベクトルを持っています。どうすればstd :: vectorに変換できますか?dlibの行列をstd :: vectorに変換する方法
typedef dlib::matrix<double,0,1> column_vector;
column_vector starting_point(4);
starting_point = 1,2,3,4;
std::vector x = ??
おかげ
多くの方法があります。あなたはforループを介してそれをコピーすることができます。または、イテレータ:std::vector<double> x(starting_point.begin(), starting_point.end())
を受け取るstd :: vectorコンストラクタを使用します。
これは、あなたが通常(行列が1つだけの列を持っている場合は関係ありません)行列を反復方法だろう:
// loop over all the rows
for (unsigned int r = 0; r < starting_point.nr(); r += 1) {
// loop over all the columns
for (unsigned int c = 0; c < starting_point.nc(); c += 1) {
// do something here
}
}
だから、なぜあなたはあなたの列ベクトルを反復し、導入しません各値は新しいstd::vector
に入りますか?完全な例を次に示します。
#include <iostream>
#include <dlib/matrix.h>
typedef dlib::matrix<double,0,1> column_vector;
int main() {
column_vector starting_point(4);
starting_point = 1,2,3,4;
std::vector<double> x;
// loop over the column vector
for (unsigned int r = 0; r < starting_point.nr(); r += 1) {
x.push_back(starting_point(r,0));
}
for (std::vector<double>::iterator it = x.begin(); it != x.end(); it += 1) {
std::cout << *it << std::endl;
}
}
ありがとうございました。しかし、それは標準ではありません:: x(starting_point.begin()、starting_point.end())? –
colddie
おっと、そうです。 –