Is there any method to use cartesian product and zip in SFrame or SArray?

User 5312 | 6/21/2016, 3:28:40 AM

Hi I'm newbie to Graphlab. is there any method to cartesian product and zip in SFrame or SArray?

Comments

User 940 | 6/21/2016, 5:52:17 PM

Hi @mincheolPark ,

Although there is no explicit zip function for SArray's, there is an equivalent function called pack_columns for an SFrame.

Regarding a cartesian product, I'm not entirely sure what you mean by that. Do you mean a per-row cartesian product of two SArray's? Or treating the entire SArray as a set and doing a cartesian product of those?

Cheers! -Piotr


User 5312 | 6/22/2016, 2:11:13 AM

Hi @piotr

thanks for your answer. I found simple function <code>add_column</code> that can use instead of <code>zip</code> in SFrame :)

and cartesian product that I said means cartesian product of two list. I also found some tricky way of that

animals = graphlab.SFrame({'id': [0,0,0,0], 'name': ['dog', 'cat', 'sheep', 'cow']}) sounds = graphlab.SFrame({'id': [0,0,0,0],'sound': ['woof', 'baa', 'moo', 'oink']}) animals.join(sounds, how='outer')

do you know more elegant way?

Cheer! -mincheolPark


User 940 | 6/22/2016, 6:50:32 PM

Hi @mincheolPark ,

Unfortunately, I think the join may be your best bet. I'm curious though, what is your use case here? It seems like that kind of operation could blow up to be really big really fast.

Cheers! -Piotr


User 5312 | 6/23/2016, 3:07:23 AM

Hi @piotr

my case is making all pairs of two list.

users = ['a','b','c'] coupons = [1,2,3] expeted result usercouponpair = [['a',1],['a',2],['a',3],['b',1],['b',2],['b',3],['c',1],['c',2],['c',3]]

Cheer! -mincheolPark