[eigen] initializing a matrix so that all columns are copies of one column |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] initializing a matrix so that all columns are copies of one column
- From: Douglas Bates <bates@xxxxxxxxxxxxx>
- Date: Fri, 9 Dec 2011 15:41:22 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=OyP3Z+M9RDuSorjosovgj68VxgCEQ4GYPfNbjk5Ta28=; b=sO0faDfy4k67EZdv307un55ZmOpzllYEK9GucsXw6Zw2SyPyqZj0M6rpkghqaxH0+s AW24Li4i8QyLLfCFZjiStkcT4gssoxq2+0jwoaB9SR9gQRC6JE+7+cS6NJJ0hBansXf2 nN5aCCGz2V55Fo42ACdPqFQzBWXq1SGAbXW5c=
In an optimization algorithm I have an n by n+1 matrix whose columns
correspond to parameter vectors. At one point I want to subtract a
given n vector from each column, convert to absolute values, and find
the maximum coefficient in each row. The matrix is called pts and the
position I want to subtract is a centroid called c. If I can think of
a way of creating another n by n+1 matrix whose columns are copies of
c, let's call it cmat, then I can write
VectorXd maxdev( (pts - cmat).array().abs().rowwise().maxCoeff() );
but the best I have been able to come up with for constructing cmat is
MatrixXd cmat(n, n+1);
for (int i = 0; i <= n; ++i) cmat.col(i) = c;
Is there a more elegant way of doing this?