intersect

Python list intersection efficiency: generator or filter()?

佐手、 提交于 2019-12-01 01:57:43
问题 I would like to intersect two lists in Python (2.7). I need the result to be iterable: list1 = [1,2,3,4] list2 = [3,4,5,6] result = (3,4) # any kind of iterable Providing a full iteration will be performed first thing after the intersection, which of the following is more efficient? Using a generator: result = (x for x in list1 if x in list2) Using filter(): result = filter(lambda x: x in list2, list1) Other suggestions? Thanks in advance, Amnon 回答1: Neither of these. The best way is to use

How to use the Rect.intersect method.

点点圈 提交于 2019-11-30 21:37:18
Ive created a game where you move a rectangle and dodge other falling rectangles from the sky. Though everytime the rectangles intersect nothing happens. if(mSquare.intersect(jSquare)){ canvas.drawColor(Color.BLACK); or collision = mSquare.intersect(jSquare); if(collision==true){ canvas.drawColor(Color.RED); } this always returns false no matter where the rectangles are....... There are a lot of ways to do this, the simplest would be to get the bounding Rect for each Bitmap and on each time step to check for a collision using Rect.intersect() method. Something like this: boolean collision =

MySQL Internals-Index Merge优化 - 心中无码 - 博客园

[亡魂溺海] 提交于 2019-11-30 18:00:31
MySQL Internals-Index Merge优化 Louis Hust 0 前言 之前搞错了,以为Index Merge是MySQL5.6的新特性,原来不是,发现5.5也有,看了下manual,发现5.0的manual就已经存在了, 可以说是一个历史悠久的优化手段了,好吧,不管怎么样,今天就拨开其神秘的面纱,看看其内部到底如何生成这种Index Merge的计划的。 这里只详细介绍Intersect操作,对于Union和Sort-Union的具体代码,还没开始研究。 1 Index Merge理论基础 Index Merge——索引归并,即针对一张表,同时使用多个索引进行查询,然后将各个索引查出来的结果进行进一步的操作,可以是求交 ——Intersect,也可以是求和——Union,针对union还有一种补充算法——Sort-Union,很奇怪为什么没有Sort-Intersect,按道理也是可以做的。 什么情况下,同时使用多个索引会有利呢?比如说WHERE条件是C1=10 AND C2 =100,但是只有分别针对C1和C2的索引,而没有(C1,C2)这种索引, 两个索引同时使用才有意义,通过两个索引都可以快速定位到一批数据,然后对这一批数据进行进一步的求交或求和操作即可,这样的效率可能比 全表扫描或者只使用其中一个索引进行扫描然后再去主索引查询要快。

How to use the Rect.intersect method.

橙三吉。 提交于 2019-11-30 05:39:25
问题 Ive created a game where you move a rectangle and dodge other falling rectangles from the sky. Though everytime the rectangles intersect nothing happens. if(mSquare.intersect(jSquare)){ canvas.drawColor(Color.BLACK); or collision = mSquare.intersect(jSquare); if(collision==true){ canvas.drawColor(Color.RED); } this always returns false no matter where the rectangles are....... 回答1: There are a lot of ways to do this, the simplest would be to get the bounding Rect for each Bitmap and on each

c# dictionaries intersect

自古美人都是妖i 提交于 2019-11-29 17:09:50
问题 I have a question about Linq / Lambda and the following issue: I have two dictionaries, primary and secondary... These two dictionaries are defined as Key=string, Value=int. I need to trim down the primary dictionary if the KEYS intersect with secondary dictionary. i.e.: primaryDict = ["thing1", 33] ["thing2", 24] ["thing3", 21] ["thing4", 17] ["thing5", 12] secondaryDict = ["thing1", 22] ["thing3", 20] ["thing4", 19] ["thing7", 17] ["thing9", 10] resultDict = ["thing1", 33] ["thing3", 21] [

Intersect all possible combinations of list elements

孤街浪徒 提交于 2019-11-29 13:25:38
I have a list of vectors: > l <- list(A=c("one", "two", "three", "four"), B=c("one", "two"), C=c("two", "four", "five", "six"), D=c("six", "seven")) > l $A [1] "one" "two" "three" "four" $B [1] "one" "two" $C [1] "two" "four" "five" "six" $D [1] "six" "seven" I would like to calculate the length of the overlap between all possible pairwise combinations of the list elements , i.e. (the format of the result doesn't matter): AintB 2 AintC 2 AintD 0 BintC 1 BintD 0 CintD 1 I know combn(x, 2) can be used to get a matrix of all possible pairwise combinations in a vector and that length(intersect(a,

CSS遮罩mask

南笙酒味 提交于 2019-11-29 07:51:40
本文转载于: 猿2048 网站⇨ CSS遮罩mask 前面的话   CSS遮罩是 2008年4月 由苹果公司添加到webkit引擎中的。遮罩提供一种基于像素级别的,可以控制元素透明度的能力,类似于png24位或png32位中的alpha透明通道的效果。本文将详细介绍CSS遮罩mask 概述   遮罩mask的功能就是使用透明的图片或渐变遮罩元素的背景。于是,遮罩mask与背景background非常类似,除了没有color子属性,背景background剩下的6个子属性,mask都有   遮罩mask是一个复合属性,包括mask-image、mask-mode、mask-repeat、mask-position、mask-clip、mask-origin、mask-size、mask-composite这8个属性   [注意]IE浏览器不支持,webkit内核的浏览器(包括chrome、safari、IOS、android)需要添加-webkit-前缀。要特别注意的是,firefox浏览器也支持webkit-mask属性 【mask-image】   默认值为none,值为透明图片,或透明渐变 【mask-repeat】   默认值为repeat,可选值与background-repeat相同,详细情况 移步至此 【mask-position】   默认值为0 0

Leetcode PHP题解--D117 599. Minimum Index Sum of Two Lists

筅森魡賤 提交于 2019-11-29 06:16:01
D117 599. Minimum Index Sum of Two Lists 题目链接 599. Minimum Index Sum of Two Lists 题目分析 给定两个数组,返回其交集,在交集中返回他们在各自数组的下标之和最小。 思路 因为去找一个元素在不在另一个数组的话,需要逐个比较。因此我们在这里先把两个数组都翻过来,用isset函数去判断是否存在元素。 在循环体外保存最小和,判断两个相同的元素的下标之和是否小于最小值。是则替换,并置空交集数组。否则判断是否相等于当前最小值。相等则追加进交集数组。不相等说明大于最小值,抛弃即可。 最终代码 <?php class Solution { /** * @param String[] $list1 * @param String[] $list2 * @return String[] */ function findRestaurant($list1, $list2) { $list1 = array_flip($list1); $list2 = array_flip($list2); $min = 99999999999; $intersect = []; foreach($list1 as $name => $v){ if(!isset($list2[$name])){ continue; } if($v+

一波骚操作,我把 SQL 执行效率提高了 10,000,000 倍

血红的双手。 提交于 2019-11-29 00:34:12
场景 我用的数据库是mysql5.6,下面简单的介绍下场景 课程表: 数据100条 学生表: 数据70000条 学生成绩表SC 数据70w条 查询目的:查找语文考100分的考生 查询语句: select s.* from Student s where s.s_id in (select s_id from SC sc where sc.c_id = 0 and sc.score = 100 ) 执行时间: 30248.271s 晕,为什么这么慢 ,先来查看下查询计划: 发现没有用到索引,type全是ALL,那么首先想到的就是建立一个索引,建立索引的字段当然是在where条件的字段。 先给sc表的c_id和score建个索引 CREATE index sc_c_id_index on SC(c_id); CREATE index sc_score_index on SC(score); 再次执行上述查询语句,时间为: 1.054s 快了3w多倍,大大缩短了查询时间,看来索引能极大程度的提高查询效率,建索引很有必要。很多时候都忘记建索引了,数据量小的的时候压根没感觉,这优化的感觉挺爽。 但是1s的时间还是太长了,还能进行优化吗,仔细看执行计划: 补充:这里有朋友问怎么查看优化后的语句,方法如下: 在命令窗口执行 有type=all 按照我之前的想法

Finding common rows (intersection) in two Pandas dataframes

孤街浪徒 提交于 2019-11-28 16:31:25
Assume I have two dataframes of this format (call them df1 and df2 ): +------------------------+------------------------+--------+ | user_id | business_id | rating | +------------------------+------------------------+--------+ | rLtl8ZkDX5vH5nAx9C3q5Q | eIxSLxzIlfExI6vgAbn2JA | 4 | | C6IOtaaYdLIT5fWd7ZYIuA | eIxSLxzIlfExI6vgAbn2JA | 5 | | mlBC3pN9GXlUUfQi1qBBZA | KoIRdcIfh3XWxiCeV1BDmA | 3 | +------------------------+------------------------+--------+ I'm looking to get a dataframe of all the rows that have a common user_id in df1 and df2 . (ie. if a user_id is in both df1 and df2 , include