Re: [eigen] initializing a matrix so that all columns are copies of one column
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: Re: [eigen] initializing a matrix so that all columns are copies of one column
• From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
• Date: Fri, 9 Dec 2011 23:15:22 +0100
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=nrm8/Wji9+RraoAv4pY3p/xzhXE/WBrKChwGJCpJSmM=; b=qpQ+NqY1z93/YB9qio8OWqAtQ5fmZY50uxfp/zkcnTYINeK3WRTOG6HOEdT/F6pcGP a/yUcjRNpbRp9EQNL5Kaq8uTdTHYA7tMRQlWfw0+FSDEXHwtlWY+IK8WPYPGLzoE/Z6D 7GKZq+yntplFQ66c1k6z+IY5eHdAGYrLaARCI=

```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).

gael

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/