This forum has been archived. All content is frozen. Please use KDE Discuss instead.

succinct way to build new vector or matrix (like Matlab)

Tags: None
(comma "," separated)
bravegag
Registered Member
Posts
52
Karma
0
Hello,

I have the following snippet where I'm computing the partial derivatives for solving the regularized ridge regression so need to avoid regularizing the first (bias) coefficient:

... + lambda*[0; thetas(2, end)]

Basically I create a new column vector by appending zero (first row) with the relevant theta elements, how can I achieve the same using Eigen in the most succinct way?

TIA,
Best regards,
Giovanni
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
... + lambda * (VectorXd(end-1) << 0, thetas.segment(2,end-2)).finish() ...

or create a tmp:
Code: Select all
VectorXd tmp(end-1);
tmp << 0, thetas.segment(2,end-2);

.. + lambda * tmp ...


You might also consider thetas.tail(end-2) if you want the last end-2 elements.
bravegag
Registered Member
Posts
52
Karma
0
Very useful, thank you!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]