cartesian-product

Cartesian Product + N x M Dynamic Array

ε祈祈猫儿з 提交于 2019-11-27 17:02:41
问题 I have looked hours for a solution without any success. Hopefully someone can help me out. I have a dynamic array of N items on M origin zip codes. For instance: Item 1: 11001, 54010, 60621 Item 2: 11001, 60621 Item 3: 60621 I want to create a new array that will look like this: Route 1: 11001, 11001, 60621 Route 2: 11001, 60621, 60621 Route 3: 54010, 11001, 60621 etc - until Route 6. Suggestions? ---------------------- Is there any way to accomplish this WITHOUT using Linq? VB.net and Linq

Mixing implicit and explicit JOINs

半城伤御伤魂 提交于 2019-11-27 14:49:02
I am having a problem with Hibernate generating invalid SQL. Specifically, mixing and matching implicit and explicit joins. This seems to be an open bug . However, I'm not sure why this is invalid SQL. I have come up with a small toy example that generates the same syntax exception. Schema CREATE TABLE Employee ( employeeID INT, name VARCHAR(255), managerEmployeeID INT ) Data INSERT INTO Employee (employeeID, name) VALUES (1, 'Gary') INSERT INTO Employee (employeeID, name, managerEmployeeID) VALUES (2, 'Bob', 1) Working SQL Both of these queries work. I realize there is a Cartesian product;

Cross product in Scala

核能气质少年 提交于 2019-11-27 13:25:39
I want to have a binary operator cross (cross-product/cartesian product) that operates with traversables in Scala: val x = Seq(1, 2) val y = List('hello', 'world', 'bye') val z = x cross y # i can chain as many traversables e.g. x cross y cross w etc assert z == ((1, 'hello'), (1, 'world'), (1, 'bye'), (2, 'hello'), (2, 'world'), (2, 'bye')) What is the best way to do this in Scala only (i.e. not using something like scalaz)? You can do this pretty straightforwardly with an implicit class and a for -comprehension in Scala 2.10: implicit class Crossable[X](xs: Traversable[X]) { def cross[Y](ys:

How to apply itertools.product to elements of a list of lists?

白昼怎懂夜的黑 提交于 2019-11-27 11:54:20
I have a list of arrays and I would like to get the cartesian product of the elements in the arrays. I will use an example to make this more concrete... itertools.product seems to do the trick but I am stuck in a little detail. arrays = [(-1,+1), (-2,+2), (-3,+3)]; If I do cp = list(itertools.product(arrays)); I get cp = cp0 = [((-1, 1),), ((-2, 2),), ((-3, 3),)] But what I want to get is cp1 = [(-1,-2,-3), (-1,-2,+3), (-1,+2,-3), (-1,+2,+3), ..., (+1,+2,-3), (+1,+2,+3)]. I have tried a few different things: cp = list(itertools.product(itertools.islice(arrays, len(arrays)))); cp = list

Is there a multi-dimensional version of arange/linspace in numpy?

假如想象 提交于 2019-11-27 10:57:41
问题 I would like a list of 2d NumPy arrays (x,y) , where each x is in {-5, -4.5, -4, -3.5, ..., 3.5, 4, 4.5, 5} and the same for y. I could do x = np.arange(-5, 5.1, 0.5) y = np.arange(-5, 5.1, 0.5) and then iterate through all possible pairs, but I'm sure there's a nicer way... I would like something back that looks like: [[-5, -5], [-5, -4.5], [-5, -4], ... [5, 5]] but the order does not matter. 回答1: You can use np.mgrid for this, it's often more convenient than np.meshgrid because it creates

print out all combinations of index

坚强是说给别人听的谎言 提交于 2019-11-27 08:45:18
问题 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

Cartesian product of streams in Java 8 as stream (using streams only)

我的梦境 提交于 2019-11-27 05:07:15
I would like to create a method which creates a stream of elements which are cartesian products of multiple given streams (aggregated to the same type at the end by a binary operator). Please note that both arguments and results are streams, not collections. For example, for two streams of {A, B} and {X, Y} I would like it produce stream of values {AX, AY, BX, BY} (simple concatenation is used for aggregating the strings). So far, I have came up with this code: private static <T> Stream<T> cartesian(BinaryOperator<T> aggregator, Stream<T>... streams) { Stream<T> result = null; for (Stream<T>

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 04:30:16
问题 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

How can I make Cartesian product with Java 8 streams?

旧巷老猫 提交于 2019-11-27 01:20:35
I have the following collection type: Map<String, Collection<String>> map; I would like to create unique combinations of each of map.size() from a single value in the collection for each Key. For example suppose the map looks like the following: A, {a1, a2, a3, ..., an} B, {b1, b2, b3, ..., bn} C, {c1, c2, c3, ..., cn} The result I would like to get would a List<Set<String>> result, looking similar to (ordering is not important, it just needs to be a 'complete' result consisting of all possible combinations): {a1, b1, c1}, {a1, b1, c2}, {a1, b1, c3}, {a1, b2, c1}, {a1, b2, c2}, {a1, b2, c3}, .

How can I compute a Cartesian product iteratively?

你说的曾经没有我的故事 提交于 2019-11-26 20:47:52
This question asks how to compute the Cartesian product of a given number of vectors. Since the number of vectors is known in advance and rather small, the solution is easily obtained with nested for loops. Now suppose that you are given, in your language of choice, a vector of vectors (or list of lists, or set of sets, etc.): l = [ [1,2,3], [4,5], [6,7], [8,9,10], [11,12], [13] ] If I was asked to compute its Cartesian product, that is [ [1,4,6,8,11,13], [1,4,6,8,12,13], [1,4,6,9,11,13], [1,4,6,9,12,13], ... ] I would proceed with recursion. For example, in quick&dirty python, def