简体   繁体   中英

GraphLab .apply to sframe

I have trying to do a very simple .apply to an sarray in graph lab create and I am confused as to why it is not working.

def myfunc (x):
if(x == 0):
    x = -1

sa = SArray([0,0,0,1,1], dtype=int)

sa.apply(myfunc, dtype = int)

My output is

[None, None, None, None, None]

Why is it not [-1, -1, -1, 1, 1] and how can I fix it?

I got it to work using

sa.apply(lambda sa : -1 if sa ==0 else sa)

but I am still not sure why what I tried above does not work...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM