Thanks for your helpful answers.

Finally, I've done following implementations:

#### which with for loop

A = matrix("1 3 5 2 4", rows=5, cols=1)

which = function (matrix[double] A) return (matrix[double] R) {

R = matrix(0, 0, 1);

n = nrow(A)

for( i in 1:n ) {

if(as.scalar(A[i,1]) > 0) {

R = rbind(R, matrix(as.integer(i), 1, 1))

}

}

}

A2 = A>2

R = which(A2)

#### which with replace (Thanks to Niketan, I've understood the removeEmpty syntax ,finally )

A = matrix("1 3 5 2 4", rows=5, cols=1)

which = function (matrix[double] A) return (matrix[double] R) {

R = removeEmpty(target=A*seq(1, nrow(A)), margin="rows")

}

C = A>2

R = which(C)

#### is.na

A = matrix("1 3 5 0 4", rows=5, cols=1)

A[3,1] = A[3,1]/0

is_na = function (matrix[double] A) return (matrix[double] R) {

R = A == 1/0

}

R = is_na(A)

Kuno

-----Original Message-----

From: Berthold Reinwald [mailto:[EMAIL PROTECTED]]

Sent: Samstag, 7. Juli 2018 02:12

To: [EMAIL PROTECTED]

Subject: Re: which() Function in SystemML

You may also look at example 2 "Replace NaN with mode" in our "DML Tips and Tricks" examples notebook. Will add a which() example shortly.

https://github.com/apache/systemml/raw/master/samples/jupyter-notebooks/DML%20Tips%20and%20Tricks%20(aka%20Fun%20With%20DML).ipynb

Regards,

Berthold Reinwald

IBM Almaden Research Center

office: (408) 927 2208; T/L: 457 2208

e-mail: [EMAIL PROTECTED]

From: "Niketan Pansare" <[EMAIL PROTECTED]>

To: [EMAIL PROTECTED]

Date: 07/05/2018 10:26 AM

Subject: Re: which() Function in SystemML

Hi Kuno,

Thanks for trying out SystemML. One way to implement your logic in SystemML is as follows:

X = matrix("1 4 -99 2 5 -99", rows=6, cols=1) Y = removeEmpty(target=(X > 2)*seq(1, nrow(X)), margin="rows") print("\nIndexes:\n" + toString(Y))

For handling NAs, you can replace NAs by certain value (in this case -99 or one of the builtin constants, i.e. Inf or NaN ... see https://github.com/apache/systemml/blob/master/src/test/scripts/org/apache/sysml/api/mlcontext/builtin-constants-test.dml

) using the "na.strings" parameter of the transform builtin function ( http://apache.github.io/systemml/dml-language-reference.html#transforming-frames

).

Hope this helps.

Regards,

Niketan Pansare

IBM Almaden Research Center

E-mail: npansar At us.ibm.com

http://researcher.watson.ibm.com/researcher/view.php?person=us-npansar

"Baeriswyl Kuno (IT-SWE-CC1-JV6)" ---07/05/2018 05:29:53 AM---Hello, I'm a developer want to use SystemMl for running R-Code from our business people on a Spark c

From: "Baeriswyl Kuno (IT-SWE-CC1-JV6)" <[EMAIL PROTECTED]>

To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>

Date: 07/05/2018 05:29 AM

Subject: which() Function in SystemML

Hello,

I'm a developer want to use SystemMl for running R-Code from our business people on a Spark cluster.

I've studied http://apache.github.io/systemml/dml-language-reference , however, haven't found a implementation of the R function "which" or any alternative functionality. Has anyone an idea how I could

# Given

v = c(1,4,NA,2, 5, NA)

# Expect indexes where value meets condition = int[] 2 5

v2 = which(v>2)

# Expect indexes where is.na returns TRUE = int[] 3 6

v3 = which(is.na(v))

I've already considered the functions replace() and removeEmpty(), but they don't exactly meets my needs.

Thanks a lot in advance

Kuno