I am trying to switch numbers between rows
here is the thing
there are 8! (40320) cases that i need to make arraying numbers in total
E.g., (8*7*6*5*4*3*2*1) : (0, 1, 2, 3, 4, 5, 6, 7) (1,0,2,3,4,5,6,7)(1,2,0,3,4,5,6,7) (1,2,3,0,4,5,6,7) .... (7,6,5,4,3,2,1,0)
so i am going to create 40320 fields and trying to put number in it.
I was thinking that i could use Random number generator but it returns duplicate number in rows and also it might have a chance to have duplicate fields.
Are there any ways that i can do this easy way using field calculator's code block?
Solved! Go to Solution.
>>> from itertools import permutations as p
>>> r = [i for i in p(range(3),3)]
>>> len(r)
6
>>> r
[(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
>>> r = [i for i in p(range(8),8)]
>>> len(r)
40320
>>>
I can help with the numbers, but you aren't going to get that number of fields.
What you want is a permutation. two examples follow... I have printed one example out and just given the length of the 2nd. I strongly don't recommend that you print it out... at least on paper
EDIT fixed line 2 Nov 10 to read ..... range(3), 3)]
I think you will not find any db system that will allow you to have a table with 40k attribute cols.
That's crazy.
If this is a bunch of arrays, then let's wait for Dan_Patterson to come up with some more elegant solution using numpy.
thanks for quick response.
yeah, i agree with that a table with 40K or more fields is crazy .. but i think that's the best way to find out the best (shortest path) route between 8 points -(calculating all the possible route and find the minimum distance among all)
if you have any advice on this, please let me know
by the way, thanks a lot
>>> from itertools import permutations as p
>>> r = [i for i in p(range(3),3)]
>>> len(r)
6
>>> r
[(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
>>> r = [i for i in p(range(8),8)]
>>> len(r)
40320
>>>
I can help with the numbers, but you aren't going to get that number of fields.
What you want is a permutation. two examples follow... I have printed one example out and just given the length of the 2nd. I strongly don't recommend that you print it out... at least on paper
EDIT fixed line 2 Nov 10 to read ..... range(3), 3)]
LOL printing them will crash my PC
thanks a lot. I will try and see how it works on my ArcMap
I have no solution, but maybe others have accomplished something similar to this idea.
Is there a way to use an image (a raster field?) as the array? This requires custom functions to store, read, and write array elements. But, this would be a very compact way to store data.
Like I said, just an idea with no clue how to implement it.
thanks for your idea
I am applying Dan's solution to this