cartesian-product

print out all combinations of index

爷,独闯天下 提交于 2019-11-28 14:47:01
I set a vector list, for example : vector<VectorXi> Test; Test.push_back(VectorXi(0,1)); Test.push_back(VectorXi(0,1,2)); Test.push_back(VectorXi(0)); Test.push_back(VectorXi(0,1)); Test.push_back(VectorXi(0,1,2,3)); PrintAllCombins(Test) And now I want to get all combinations of indexes : 0, 0, 0, 0, 0 0, 0, 0, 0, 1 0, 0, 0, 0, 2 0, 0, 0, 0, 3 0, 0, 0, 1, 0 0, 0, 0, 1, 1 0, 0, 0, 1, 2 0, 0, 0, 1, 3 0, 0, 1, 0, 0 0, 0, 1, 0, 1 0, 0, 1, 0, 2 0, 0, 1, 0, 3 ... and so on If i use for or while loop suitably, then it works I guess, but I encounter limitation. Is there any idea? I'm writing code in

Permutations of parameters (i.e. Cartesian product) into a multi-dimensional array

岁酱吖の 提交于 2019-11-28 14:10:13
I am interested in calculating a function on a bunch of permutations of parameter values. I want to keep it generic to N dimensions, but let me write it out in 3 dimensions to start with. Generating the permutations is easy enough with meshgrid , but I can't figure out how to reshape the resulting array back to the multidimensions? Here is a starting point: %These are the 3 variations of parameters, with some values. params1 = [100, 200, 300];%Picking these so it is easy to correlate to the function params2 = [10, 20]; params3 = [1, 2]; %This generates parameter_values as the cartesian

Cartesian product of objects in javascript

落爺英雄遲暮 提交于 2019-11-28 09:27:13
I need to generate a complete set of variants based on a list of N attributes, while keeping the attribute name intact. var input = [ { 'colour' : ['red', 'green'] }, { 'material' : ['cotton', 'wool', 'silk'] }, { 'shape' : ['round', 'square', 'rectangle'] } ]; var expected = [ { 'colour': 'red', 'material': 'cotton', 'shape': 'round' }, { 'colour': 'red', 'material': 'cotton', 'shape': 'square' }, { 'colour': 'red', 'material': 'cotton', 'shape': 'rectangle' }, { 'colour': 'red', 'material': 'wool', 'shape': 'round' }, { 'colour': 'red', 'material': 'wool', 'shape': 'square' }, { 'colour':

Finding cartesian product in Java

放肆的年华 提交于 2019-11-28 08:46:06
问题 I want to find cartesian product of set of elements. Here's an example example 1 : sets :(ab) (bc) (ca) cartesian product is, abc aba acc aca bbc bba bcc bca example 2 : sets : (zyx) b c cartesian product is, zbc ybc xbc So I am thinking of an algorithm to execute in java which can find cartesian product of particular amount of groups defined at compile time at the start. 回答1: You can use the Sets.cartesianProduct() method from Google's Guava libraries to generate Cartesian products: com

Cartesian product of large iterators (itertools)

ⅰ亾dé卋堺 提交于 2019-11-27 23:29:28
问题 From a previous question I learned something interesting. If Python's itertools.product is fed a series of iterators, these iterators will be converted into tuples before the Cartesian product begins. Related questions look at the source code of itertools.product to conclude that, while no intermediate results are stored in memory, tuple versions of the original iterators are created before the product iteration begins. Question : Is there a way to create an iterator to a Cartesian product

How do I compute the cartesian product of n sequences in F#?

有些话、适合烂在心里 提交于 2019-11-27 22:59:25
I was given a puzzle as a present. It consists of 4 cubes, arranged side by side. The faces of each cube are one of four colours. To solve the puzzle, the cubes must be orientated so that all four cubes' tops are different, all their fronts are different, all their backs are different and all their bottom's are different. The left and right sides do not matter. My pseudo-code solution was: Create a representation of each cube. Get all the possible orientations of each cube (there are 24 for each). Get all the possible combinations of orientations of each cube. Find the combination of

How to select specific item from cartesian product without calculating every other item

落花浮王杯 提交于 2019-11-27 21:20:55
I'm mostly convinced that there is an answer to this problem, but for the life of me can't figure out how to do it. Let's say I have three sets: A = [ 'foo', 'bar', 'baz', 'bah' ] B = [ 'wibble', 'wobble', 'weeble' ] C = [ 'nip', 'nop' ] And I know how to calculate the cartesian / cross product, (ant it's covered all over the place, on this site and elsewhere) so I won't go over that here. What I'm looking for is an algorithm that would allow me to simply select a specific item from the cartesian product without generating the whole set or iterating until I reach the nth item. Of course, I

How do I generate a Cartesian product in Java?

☆樱花仙子☆ 提交于 2019-11-27 18:13:32
问题 I have a number of ArrayList with each ArrayList having objects and each one can have different length. I need to generate permutation like in the below example: suppose i have 2 arraylist arraylist A has object a, object b and object c arraylist B has object d, object e Then the output should be 6 new arraylist with this combinations: combination 1 object a and object d, combination 2 object a and object e, combination 3 object b and object d, combination 4 object b and object e, combination

MemoryError while creating cartesian product in Numpy

情到浓时终转凉″ 提交于 2019-11-27 18:12:36
问题 I have 3 numpy arrays and need to form the cartesian product between them. Dimensions of the arrays are not fixed, so they can take different values, one example could be A=(10000, 50), B=(40, 50), C=(10000,50). Then, I perform some processing (like a+b-c) Below is the function that I am using for the product. def cartesian_2d(arrays, out=None): arrays = [np.asarray(x) for x in arrays] dtype = arrays[0].dtype n = np.prod([x.shape[0] for x in arrays]) if out is None: out = np.empty([n, len

Calculate n-ary Cartesian Product

妖精的绣舞 提交于 2019-11-27 17:51:54
问题 Given two lists, I can produce a list of all permutations the Cartesian Product of these two lists: permute :: [a] -> [a] -> [[a]] permute xs ys = [ [x, y] | x <- xs, y <- ys ] Example> permute [1,2] [3,4] == [ [1,3], [1,4], [2,3], [2,4] ] How do I extend permute so that instead of taking two lists, it takes a list (length n) of lists and returns a list of lists (length n) permute :: [[a]] -> [[a]] Example> permute [ [1,2], [3,4], [5,6] ] == [ [1,3,5], [1,3,6], [1,4,5], [1,4,6] ] --etc I