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

Creating a "Masked" Array/Matrix

Tags: None
(comma "," separated)
MMU
Registered Member
Posts
10
Karma
0

Creating a "Masked" Array/Matrix

Tue Dec 06, 2011 7:59 pm
Greetings,

I have been migrating some code to C++ from python. I used numpy in python and more specifically I used the "masked array" object. Not sure if anyone is familiar with it, but it is basically a data array that has an accompanying boolean array (the mask) that has True in positions where the value is considered "missing". So far I have been able to replicate the functionality I need in C++ by just wrapping two Eigen arrays (one for data, one for the bools) into one object with a couple of simple helper methods.

However I now need some of the more advanced functionality that did special things based on the mask: basically the sum(), mean(), etc. methods for masked arrays would automatically not include the missing values when doing its calculation,

e.g. [1, 99, 99, 4], mask=[0, 1, 1, 0]
the sum of this, row wise, would be 5. The .sum() function would automatically exclude the 99's because they were masked.

The only way I can think of doing something like this in Eigen is by writing my own sum method that did the summation itself, checking the mask as it sums. Is there any way that I could use some of the built in functionality of Eigen (like .rowwise() for example) to avoid brute force looping?

I realize this is sort of a broad topic, but I'm more concerned currently with the sum functionality I describe above, in that if I have an array with data and a corresponding array full of bools (the mask), could there be a way to receive a result from array.rowwise().sum() where the sum() excluded the values where the mask was True. I am hoping maybe someone more familiar with Eigen and how you can manipulate it's features could think of or have an idea about how you could do this.

Thank you very much for your time.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
this is a planed feature, just need to find time or someone willing to do it.
sth4nth
Registered Member
Posts
13
Karma
0
Please implement this. This is a really useful feature. I use it in Matlab a lot.


Bookmarks



Who is online

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