Re: [eigen] initializing a matrix so that all columns are copies of one column

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


On Fri, Dec 9, 2011 at 4:15 PM, Gael Guennebaud
<gael.guennebaud@xxxxxxxxx> wrote:
> here you go:
>
> VectorXd maxdev(pts.colwise() - c).array().abs().rowwise().maxCoeff();
>
> You can also use replicate(...) to form an expression of cmat (see the
> documentation of replicate).

Thank you.

> On Fri, Dec 9, 2011 at 10:41 PM, Douglas Bates <bates@xxxxxxxxxxxxx> wrote:
>> 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?
>>
>>
>
>



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