问题标签 [intersection]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
1470 浏览

ruby - Ruby 数组交集,Hash.has_value?用于基于哈希值与数组[i+1] 的交集

我正在尝试使用基于哈希值的数组和哈希的交集填充数组:

对于哈希值 和 的交集效果很好array2[i],但是如果我想用来自 的array2[i+1]元素填充array2,我会迷路。

也试过:

但没有运气。

有任何想法吗?

0 投票
1 回答
251 浏览

ruby - 如何进行许多<-->许多 DataMapper 集合的交集?

我正在尝试返回与标记主题相关的数据映射器集合的交集。

在我们进一步讨论之前,我应该指出显而易见的:

这将返回一个 UNION,这意味着我得到所有带有“shim”或“sham”作为标签的主题。

我想要做的是返回所有带有“shim”和“sham”作为标签的文章。

好的,我们有了数据——现在我们还有一个问题。我们需要把它作为一个 DataMapper 集合,这样我就可以像这样有效地钻取我的结果:

这当然是不可能的,因为@blah 现在是一个数组而不是 DataMapper 集合。

上述更简洁的版本:

虽然我们仍然得到一个数组.....根据http://www.mail-archive.com/datamapper@googlegroups.com/msg02092.html这应该是可能的

0 投票
6 回答
4913 浏览

python - 比较 Python 嵌套列表

我有两个嵌套列表,每个嵌套列表包含两个字符串,例如:

我想比较这两个列表并恢复那些彼此相同的嵌套列表。在这种情况下,只会('DEF','[2,3,4]')被退回。清单可能会很长。有没有一种有效的方法来做到这一点?

0 投票
6 回答
8091 浏览

geometry - 确定坐标是否存在于多边形内部

我正在开发一个开源跟踪和地理围栏软件应用程序,并且在弄清楚地理围栏的数学方面有点困难。

我需要确定多边形内部是否存在坐标。然而,棘手的部分是多边形没有固定的边数。我需要能够计算五十面或五面。

我的研究表明,最简单的方法是获取我的点(我将其称为 x)和多边形外的一个点(称为 y)并确定线 ((xx, xy), (yx, yy)) 是否与多边形的边界。如果它相交奇数次,点 x 必须在多边形内。

然而,知道这一点,我无法弄清楚如何在算法中表达这一点。我显然需要遍历构造多边形的各种线,但我所做的检查却让我望而却步。任何人都可以提供帮助吗?请知道我不一定要求解决方案。任何能帮助我找出答案的东西都是巨大的帮助。

非常感激。

0 投票
5 回答
803 浏览

sql - 如何有效地在 SQL 中进行连接的交集?

我有三个表,bookstagstaggings( books-xref-tags):

我想搜索所有标记为“有趣”“小说”的书籍。我想出的最好的是

这似乎可行,但我不确定它将如何缩放,无论是行还是标签数量。也就是说,当我添加数百本书、数百个标签和数千个标签时会发生什么?当搜索变成“‘有趣’ ‘虚构’ ‘水生’‘石工’”时会发生什么?

如果没有更好的方法直接在 SQL 中进行查询,我会考虑另一种方法:

  1. 选择所有带有第一个标签的书,以及所有这些书的标签
  2. 从列表中删除任何没有查询到所有标签的内容
0 投票
4 回答
12827 浏览

algorithm - 测试线段是否与球体相交

我正在尝试确定线段(即两点之间)是否与球体相交。我对交叉点的位置不感兴趣,只关心线段是否与球面相交。有人对最有效的算法有什么建议吗?(我想知道是否有比通常的射线球相交算法更简单的算法,因为我对相交位置不感兴趣)

0 投票
1 回答
429 浏览

sequence - Mathematical technique to check intersection

Imagine there is a very very large room in the shape of a hollow cube. There are magic balls hanging in the air at fixed discrete positions of the room. No magic ball has another one exactly above it. If we take an imaginary horizontal plane of infinite area and pass through the cube, how can we be sure that the plane doesn't cut through any of the magic balls ?

The height of a magic ball is given as a function of its position (x and y). The distribution is such a way that some balls are at the same height while other are at different heights. Let the function be
z = axy + bx + cy
where a,b,c are positive integer constants. The positions (x-axis and y-axis values) and also the height (z) are discrete values (for simplicity, we can consider them positive integers).

If the ball distribution function was z=10xy+8x+4y, then it is impossible to have a z value of 15 or 21. So a plane at z=15 or z=21 would not cut any of the balls! In fact, in this case, any plane with a height (z = any odd number) would not cut through the balls. It is noticeable that there a some planes with height as even numbers that donot cut through the balls.

We do not want to find the heights of all the magic balls and compare it with the height of the horizontal plane, as that would be like trying all the possible combinations and would take very long time even on a computer.

Our aim is to find a fast method by which we can tell whether a given value of z (height) can be produced by any pair of (x,y) (positions).If a given z cannot be produced, then a plane at that height doesn't cut through any balls! The question is also similar to finding whether a given number is present in a sequence produced by a function of two variables.

It would a great help if U could give me any suggestions to solve this problem. Thank You. (I have already tried evolutionary computing like GA,PSO,DE,SA etc. The method needs to be deterministic).

0 投票
1 回答
397 浏览

php - array_intersect_key PHP 数组与 MYSQL 数据库

我在 PHP 中有一个简单的数组,比如说

我想查询一个MYSQL数据库

我只希望接收 PHP 数组和数据库索引列之间的交叉行。所以这会导致

有任何想法吗?谢谢!

0 投票
4 回答
9717 浏览

c# - 查找所有相交数据,而不仅仅是唯一值

我以为我明白Intersect了,但事实证明我错了。

我可以想办法:

LINQ 中是否有更简单的方法来实现这一点?

我确实需要声明,我不在乎给出结果的顺序。

2,2,2,3,3,3,3 也完全可以。

问题是我在一个非常大的集合上使用它,所以我需要效率。

我们谈论的是对象,而不是整数。整数只是为了简单的例子,但我意识到这可以有所作为。

0 投票
4 回答
24978 浏览

python - 在python中有效地知道两个列表的交集是否为空

假设我有两个列表,L 和 M。现在我想知道它们是否共享一个元素。如果他们共享一个元素,哪一种是询问(在 python 中)的最快方法?我不在乎他们共享哪些元素,或者有多少,只是他们是否共享。

例如,在这种情况下

我应该得到 False,在这里:

我应该得到真实的。

我希望这个问题很清楚。谢谢!

曼努埃尔