systemml-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthias Boehm <mboe...@googlemail.com>
Subject Re: Updating A Vector
Date Fri, 28 Apr 2017 04:46:47 GMT
if your values in matrix2 are aligned as in your example, then you can do
the following (which works for arbitrary values in matrix1 but you could
simplify it if you have just 1s):

matrix1 = matrix1*(matrix2==0) + (matrix2!=0)*2;

The only problematic case would be special values such NaNs in matrix1
because they cannot be pruned away due to NaN * 0 = NaN, but you can use
our replace builtin function to eliminate NaNs before that.

Regards,
Matthias

On Thu, Apr 27, 2017 at 9:46 AM, arijit chakraborty <akc14@hotmail.com>
wrote:

> Hi,
>
>
> I've 2 matrix:
>
>
> matrix1 = matrix(1, 10, 1)
>
> matrix2 = matrix(seq(1,10,1),1,1)
>
>
> matrix1 value will be updated based on matrix2. E.g. suppose in matrix2,
> only 2, 3, 4 position has value and rest has 0, then matrix1 value will be
> updated to, say 2, for position 2,3,4. So the new matrix looks like this:
>
>
> matrix1 = matrix("1 2 2 2 1 1 1 1 1 1", 10, 1)
>
> matrix2 = matrix("0 2 3 4 0 0 0 0 0 0", 10, 1)
>
>
> I used the following code to update the matrix:
>
>
> matrix2_1 = removeEmpty(target = matrix2, margin = "rows");
>
>
> for(k in 1:nrow(matrix2_1 )){
>
> matrix1 [as.scalar(matrix2_1 [k,]),] = 2
>
> }
>
> This code works, but I would like this calculation in matrix form. I tried
> it using "table" function. But I'm yet to understand fully the use of
> "table".  So unable to do it.
>
> Can anyone please help me to solve the problem?
>
> Thank you!
> Arijit
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message