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

accessing/assigning based on a boolean array

Tags: None
(comma "," separated)
wingsit
Registered Member
Posts
28
Karma
0
OS
Hi all

Maybe it is somewhere in the documentations but I havent been able to find it. Is there a simple way to access/assigning to substructure similar to the expression

Code: Select all
b = bit-array in whatever convenient structure;
a[b] = something;


Similar to matlabs

Code: Select all
b = (a == 0);
a(b) =something;


Thanks,

Leon
wingsit
Registered Member
Posts
28
Karma
0
OS
further digging into the forum, it seems that there is not simple way to perform the action above.

Just for reference, IT++ seems to provide something along this line and it is also a template matrix library.

http://itpp.sourceforge.net/current/users_guide.html
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Seems like what you're after is select().

http://eigen.tuxfamily.org/dox/classEig ... 24a4884807

search this forum for usage examples.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
wingsit
Registered Member
Posts
28
Karma
0
OS
bjacob wrote:Seems like what you're after is select().

http://eigen.tuxfamily.org/dox/classEig ... 24a4884807

search this forum for usage examples.


Your answer has always been very helpful. Thank you very much for your time.
Select() does some of what I need but I ultimately wants to have the reference to the SUB-matrix based on the bool vec. This might be difficult in c++ because the size of the resulting matrix is only known at run-time and the pattern of boolean vector is not determined at compile-time.


Something like



Code: Select all
>> a  = rand(3)
a =
    0.9049    0.1111    0.5949
    0.9797    0.2581    0.2622
    0.4389    0.4087    0.6028
>> b = rand(1,3)>0.5
b =
     1     0     0
>> a(b,:)
ans =
    0.9049    0.1111    0.5949 //which is a submatrix reference to a

User avatar
bjacob
Registered Member
Posts
658
Karma
3
Sorry, you have to construct that by hand with a for loop. The good news is that this isn't going to be slower than anything we could do within Eigen (e.g. this is not vectorizable anyway).


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
wingsit
Registered Member
Posts
28
Karma
0
OS
bjacob wrote:Sorry, you have to construct that by hand with a for loop. The good news is that this isn't going to be slower than anything we could do within Eigen (e.g. this is not vectorizable anyway).



Fair enough. Thanks!


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]