[eigen] Efficiently creating a matrix of pairwise vector differences. |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: "eigen@xxxxxxxxxxxxxxxxxxx" <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: [eigen] Efficiently creating a matrix of pairwise vector differences.*From*: "Smith, Louis" <Louis_Smith@xxxxxxxxxxxxxxxxxx>*Date*: Wed, 20 Dec 2017 23:10:19 +0000*Accept-language*: en-US*Thread-index*: AQHTeeahgRgpiRgMkEWP93y48cTDKA==*Thread-topic*: Efficiently creating a matrix of pairwise vector differences.

Hello,
I'm trying to use eigen to compute the distances between m length vectors i and j which are each rows in an NxM matrix (note that M is often much much smaller than N. In my test case N is about 250,000 and M is 6). What I'm currently working with is an _expression_ like:
Matrix Xd data = "" //This works when data is written to cout, so elided.
MatrixXd distances = (data.rowwise() - data.transpose().colwise().transpose()).norm();
Which gives me the following error: error: no member named 'transpose' in 'Eigen::VectorwiseOp<Eigen::Transpose<Eigen::Matrix<double, -1, -1, 0, -1, -1> >, 0>'
When I get rid of the third transpose I'm then subtracting a column vector from a row vector, which also doesn't work. Calling transpose on the row vector gives a similar error.
What I expect distances to be is an NxN symmetric matrix containing the distances (norms of difference vectors) for each pair of row vectors in data.
Sorry for the newbie question, but I'd really appreciate some insight on this since it seems like there should be a more eigeny way to write this than the double-for loop over the data, which also works but is very slow.
Regards, Louis |

**Follow-Ups**:**Re: [eigen] Efficiently creating a matrix of pairwise vector differences.***From:*Gael Guennebaud

**Re: [eigen] Efficiently creating a matrix of pairwise vector differences.***From:*Jeff Hammond

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Help to compile/run unit tests for next 3.3.5 release** - Next by Date:
**[eigen] SparseMatrix StorageIndex issue** - Previous by thread:
**Re: [eigen] Compiler error with stableNorm** - Next by thread:
**Re: [eigen] Efficiently creating a matrix of pairwise vector differences.**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |