permutation

numpy array to permutation matrix

北慕城南 提交于 2019-12-19 04:09:16
问题 np.array([1,2,3]) I've got numpy array. I would like to turn it into a numpy array with tuples of each 1:1 permutation. Like this: np.array([ [(1,1),(1,2),(1,3)], [(2,1),(2,2),(2,3)], [(3,1),(3,2),(3,3)], ]) Any thoughts on how to do this efficiently? I need to do this operation a few million times. 回答1: If you're working with numpy, don't work with tuples. Use its power and add another dimension of size two. My recommendation is: x = np.array([1,2,3]) np.vstack(([np.vstack((x, x, x))], [np

Efficient search for permutations that contain sub-permutations via array operations?

时光怂恿深爱的人放手 提交于 2019-12-19 03:33:38
问题 I have a set of integers, say S = {1,...,10}, and two matrices N and M, whose rows are some (but not necessarily all possible) permutations of elements from S of orders, say, 3 and 5 respectively, e.g. N = [1 2 3; 2 5 3;...], M = [1 2 3 4 5; 2 4 7 8 1;...]. A sub-permutation Q of a permutation P is just an indexed subset of P such that the order of the indices of the elements of Q is the same as the order of their indices in P. Example: [2,4,7] is a sub-permutation of [2,3,4,6,7,1], but [1,2

Efficient search for permutations that contain sub-permutations via array operations?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 03:33:25
问题 I have a set of integers, say S = {1,...,10}, and two matrices N and M, whose rows are some (but not necessarily all possible) permutations of elements from S of orders, say, 3 and 5 respectively, e.g. N = [1 2 3; 2 5 3;...], M = [1 2 3 4 5; 2 4 7 8 1;...]. A sub-permutation Q of a permutation P is just an indexed subset of P such that the order of the indices of the elements of Q is the same as the order of their indices in P. Example: [2,4,7] is a sub-permutation of [2,3,4,6,7,1], but [1,2

Efficient search for permutations that contain sub-permutations via array operations?

◇◆丶佛笑我妖孽 提交于 2019-12-19 03:33:21
问题 I have a set of integers, say S = {1,...,10}, and two matrices N and M, whose rows are some (but not necessarily all possible) permutations of elements from S of orders, say, 3 and 5 respectively, e.g. N = [1 2 3; 2 5 3;...], M = [1 2 3 4 5; 2 4 7 8 1;...]. A sub-permutation Q of a permutation P is just an indexed subset of P such that the order of the indices of the elements of Q is the same as the order of their indices in P. Example: [2,4,7] is a sub-permutation of [2,3,4,6,7,1], but [1,2

How to access list permutations in prolog?

风格不统一 提交于 2019-12-18 13:38:30
问题 I want to access list permutation and pass it as argument to other functions. This is the permutation code: takeout(X,[X|R],R). takeout(X,[F|R],[F|S]) :- takeout(X,R,S), write(S). perm([X|Y],Z) :- perm(Y,W), takeout(X,Z,W). perm([],[]). 回答1: To start with, let's redefine your predicates so they don't do any unnecessary I/O: takeout(X,[X|R],R). takeout(X,[F |R],[F|S]) :- takeout(X,R,S). perm([X|Y],Z) :- perm(Y,W), takeout(X,Z,W). perm([],[]). Now you have what could be considered a "pure"

Generating circular shifts / reduced Latin Squares in Python

梦想与她 提交于 2019-12-18 13:33:06
问题 Was just wondering what's the most efficient way of generating all the circular shifts of a list in Python. In either direction. For example, given a list [1, 2, 3, 4] , I want to generate either: [[1, 2, 3, 4], [4, 1, 2, 3], [3, 4, 1, 2], [2, 3, 4, 1]] where the next permutation is generated by moving the last element to the front, or: [[1, 2, 3, 4], [2, 3, 4, 1], [3, 4, 1, 2], [4, 1, 2, 3]] where the next permutation is generated by moving the first element to the back. The second case is

Python permutations with constraints

强颜欢笑 提交于 2019-12-18 11:13:12
问题 I am using python 3 and I am trying to find a way to get all the permutations of a list while enforcing some constraints. For instance, I have a list L=[1, 2, 3, 4, 5, 6, 7] I want to find all permutations. However, My constraints are: 1 should always come before 2. 3 should come before 4 which in turn should come before 5. Finally, 6 should come before 7. Of course, I can generate all permutations and ignore those which do not follow these constraints but this wouldn't be efficient I guess.

How do I generate all permutations of a list of numbers?

和自甴很熟 提交于 2019-12-18 08:56:49
问题 How do I generate all possible permutations of a list of numbers in C? As an example, [1, 8, 12] would generate [1, 12, 8], [12, 8, 1], [12, 1, 8], ... 回答1: Have a look at this Johnson-Trotter Algorithm and applet it is exactly what you want. 来源: https://stackoverflow.com/questions/4270805/how-do-i-generate-all-permutations-of-a-list-of-numbers

How do I generate permutations of length LEN given a list of N Items?

微笑、不失礼 提交于 2019-12-18 07:33:42
问题 Note: I'm working in python on this. For example, given a list: list = ['a','b','c','d','e','f','g','h','i','j'] I want to generate a list of lists with all possible 3-item combinations: ['a','b','c'], ['a','b','d'], ['a','b','e'] The permutations should not use the same item twice in a permutation, but the order is important and represents distinct permutations that should be included, e.g., ['a','b','c'], ['a','c','b'] Should both be included. "3" is the magic length for the permutations I

How do I generate permutations of length LEN given a list of N Items?

浪尽此生 提交于 2019-12-18 07:33:29
问题 Note: I'm working in python on this. For example, given a list: list = ['a','b','c','d','e','f','g','h','i','j'] I want to generate a list of lists with all possible 3-item combinations: ['a','b','c'], ['a','b','d'], ['a','b','e'] The permutations should not use the same item twice in a permutation, but the order is important and represents distinct permutations that should be included, e.g., ['a','b','c'], ['a','c','b'] Should both be included. "3" is the magic length for the permutations I