Skip to main content
14 events
when toggle format what by license comment
Mar 26, 2017 at 22:24 vote accept CommunityBot
Mar 26, 2017 at 10:04 comment added Alex Hall @SirJamesofGmail see my update.
Mar 26, 2017 at 5:28 comment added user7764561 For example, for the data set data = ([2,0,0,0], [0,3,0,4], [0,0,5,0], [0,6,0,7]) using permutations(data) returns 96 possibilities, using [[row[y] for row, y in zip(data, perm)] for perm in permutations(range(len(data)))] returns 24 possibilities, but ignoring/skipping possibilities containing 0 would return only 2 possibilities: ([2,3,5,7],[2,6,5,4]) @AlexHall
Mar 26, 2017 at 5:06 comment added user7764561 Yes, since my set is large (approximately a 100 x 100 grid), I intend to control the otherwise huge number of permutations by 1) constraining the iterable to only find permutations where both the column and row are unique (as you have kindly helped me to do), and 2) by forcing that iterable to skip any permutation that contains the value 0 (I have previously removed a vast number of possibilities by converting values above a threshold to 0). Is there a way to call 'next()' on the '[[row[y] for row, y in zip... in permutations(range(len(dist)))]' if it would contain '0'? @Alex Hall
Mar 25, 2017 at 20:06 comment added Alex Hall If your real data set is very large this whole thing is bound to fail. Numbers of permutations grow very quickly.
Mar 25, 2017 at 19:58 vote accept CommunityBot
Mar 26, 2017 at 22:24
Mar 25, 2017 at 19:55 comment added user7764561 Thanks for the comments. I've tried calling itertools permutations on my array, but that returns all possible combinations where only the row is unique. I also began writing a recursive loop but then scrapped it early on: my real data set is very large and I need something more memory efficient.
Mar 24, 2017 at 23:48 review Close votes
Mar 28, 2017 at 0:04
Mar 24, 2017 at 23:26 comment added Alex Lang take your output from itertools.permutations and pass it to the built in set() function, that will get rid of duplicates.
Mar 24, 2017 at 23:24 answer added Alex Hall timeline score: 1
Mar 24, 2017 at 23:23 comment added TemporalWolf Welcome to Stack Overflow. We're not a code writing service, so please review How to Ask and show us what you've tried.
Mar 24, 2017 at 23:21 review First posts
Mar 25, 2017 at 0:03
Mar 24, 2017 at 23:21 comment added vallentin What did you try?
Mar 24, 2017 at 23:20 history asked user7764561 CC BY-SA 3.0