compare two SArray and get the maximum value for new SArray

User 2013 | 8/17/2015, 6:09:34 PM

For SArray, we could do basic mathematical operation, like, +-*/. Is there some function we could get the maximum/minimum value between two/more SArray for new SArray? e.g. newarray = max( array1, array2, array3)



User 15 | 8/17/2015, 6:23:23 PM

You can do an apply operation over an SFrame as well as an SArray, and in this case the row is passed to your function as a python dictionary. So you can do something like this:

<pre> sf = gl.SFrame({'a':[1,2,3],'b':[2,1,4]}) sf.apply(lambda x: max(x['a'], x['b'])) </pre>

and the result will be an SArray like this: <pre> dtype: int Rows: 3 [2L, 2L, 4L] </pre>

User 1592 | 8/17/2015, 6:26:28 PM

One option is array1.append(array2).append(array3).max()

Not sure if there is a more efficient way to do it.