标签: intersection

根据另一个 DataFrame 选择一个 DataFrame 的列

我试图根据另一个 DataFrame 的列选择 DataFrame 的子集。

数据框看起来像这样:

    a   b   c   d
0   0   1   2   3
1   4   5   6   7
2   8   9  10  11
3  12  13  14  15
Run Code Online (Sandbox Code Playgroud)

   a  b
0  0  1
1  2  3
2  4  5
3  6  7
4  8  9
Run Code Online (Sandbox Code Playgroud)

我想获取第一个数据帧的所有行,以获取两个数据帧中包含的列。我的结果应该是这样的:

    a   b   
0   0   1   
1   4   5   
2   8   9  
3  12  13    
Run Code Online (Sandbox Code Playgroud)

python indexing intersection dataframe pandas

5
推荐指数
2
解决办法
1万
查看次数

Python3 就运行时而言,输入顺序对于 .intersection() 函数重要吗?

假设您有两个集合,set1 非常大(几百万个值),而 set2 相对较小(几十万个值)。如果我想使用 .interstion() 函数获取这两个集合之间的值的交集,是否会根据输入的顺序改进运行时?

例如,其中一个会比另一个运行得更快吗?

set1.intersection(set2)
set2.intersection(set1)
Run Code Online (Sandbox Code Playgroud)

python runtime intersection set python-3.x

5
推荐指数
1
解决办法
338
查看次数

Intersection Observer针对不同窗口大小进行微调

到目前为止,这是我的代码:

const mediaInViewport = document.querySelectorAll('.media');
const links = Array.from(document.querySelectorAll('.link'));
let actLink = links[0];

document.body.addEventListener('click', (event) => {
  if (event.target.tagName === 'a') {
    actLink.classList.remove('active');
    actLink = links.find(link => event.target.href === link.href)
    actLink.classList.add('active');
  }
}, false)

observer = new IntersectionObserver((entries, observer) => {
  entries.forEach((entry) => {
    if (entry.target && entry.isIntersecting) {
      const closestParent = entry.target.closest('section');
      if (closestParent) {
        actLink.classList.remove('active');
        actLink = links.find(link =>
          link.href.slice(link.href.lastIndexOf('#')) === `#${closestParent.id}`
        )
        actLink.classList.add('active');
      }
    }
  });
}, {
  threshold: 0
});

window.addEventListener('DOMContentLoaded', () => {
  setTimeout( // …
Run Code Online (Sandbox Code Playgroud)

javascript intersection intersection-observer

5
推荐指数
1
解决办法
1208
查看次数

AABB 与胶囊(扫掠球体)之间的交点

A我在 R3 空间中有一个由最小向量和 最大向量定义的轴对齐边界框,以及由具有端点和和半径的B线段定义的胶囊。我想检查这两个形状是否相交。abr

我知道如果胶囊的定义线段与 AABB 相交,这两个形状实际上会相交。然而,我该如何处理剩余的情况,其中线段不与 AABB 相交,但胶囊仍然与 AABB 相交。

geometry intersection computational-geometry

5
推荐指数
1
解决办法
1248
查看次数

How to efficiently find the inverse intersection between two large dataframes with pandas?

I am trying to find the inverse intersection between two large dataframes. I got it to work with the code snipped hereafter. Unfortunately, this approach is "too slow" on large dataframes as is further described below. Can you think of a quicker way to compute this outcome?

import pandas as pd

df_1 = pd.DataFrame({'a': [8, 2, 2],
                     'b': [0, 1, 3],
                     'c': [0, 2, 2],
                     'd': [0, 2, 2],
                     'e': [0, 2, 2]})

df_2 = pd.DataFrame({'a': [8, 2, 2, 2, …
Run Code Online (Sandbox Code Playgroud)

python intersection bigdata dataframe pandas

5
推荐指数
1
解决办法
1397
查看次数

具有共享属性的 Typescript 交集

我正在尝试更好地理解 Typescript 接口。

我定义了以下接口:

interface Bob<T> { 
  x : number; 
  y : string;
  z? : T;
}

interface Jennie<T> { 
  x : number; 
  y : number;
  q : number;
  z? : T;
}
Run Code Online (Sandbox Code Playgroud)

接下来我创建了这个变量:

let myIntersection : Bob<string> & Jennie<number> = {
  x: 20, y: 'hi', q: 30, z: 20
}
    
console.log(myIntersection);
Run Code Online (Sandbox Code Playgroud)

这会引发错误:

  solution.ts:3:3
3   y : string;
    ~
The expected type comes from property 'y' which is declared here on type 'Bob<string> & Jennie<number>'solution.ts:49:24 - error TS2322: Type 'number' …
Run Code Online (Sandbox Code Playgroud)

types intersection typescript typescript-generics

5
推荐指数
0
解决办法
857
查看次数

检查 R 中的多边形交集:sf::intersects 错误地返回 TRUE 结果,而 rgeos::gIntersects 正确返回 FALSE

我正在尝试检查两个多边形是否在 R 中相交。绘图时,它们显然没有相交。检查交集时,rgeos::gIntersects()当前返回FALSE,而sf::intersects()返回TRUE。我想这是因为多边形(1)大并且(2)靠得很近,所以当在平坦的表面上时它们似乎不相交,但在球体上它们似乎相交?

理想情况下,我可以将我的工作流程全部保留下来sf——但我想知道是否有一种方法可以使用sf::intersects()(或另一个sf函数)返回FALSE这里?

这是一个例子:

library(sf)
library(rgeos)
library(leaflet)
library(leaflet.extras)

#### Make Polygons
poly_1 <- c(xmin = -124.75961, ymin = 49.53330, xmax = -113.77328, ymax = 56.15249) %>% 
  st_bbox() %>%
  st_as_sfc()
st_crs(poly_1) <- 4326

poly_2 <- c(xmin = -124.73214, ymin = 25.11625, xmax = -66.94889, ymax = 49.38330) %>% 
  st_bbox() %>%
  st_as_sfc()
st_crs(poly_2) <- 4326

#### Plotting
# Visually, the polygons do not intersect
leaflet() …
Run Code Online (Sandbox Code Playgroud)

intersection r projection r-sf rgeo-shapefile

5
推荐指数
1
解决办法
476
查看次数

测试线段是否与球体相交

我试图确定线段(即两点之间)是否与球体相交.我对交点的位置不感兴趣,只是该段是否与球体表面相交.有没有人对这个最有效的算法是什么有任何建议?(我想知道是否有任何算法比通常的射线球交叉算法更简单,因为我对交叉位置不感兴趣)

algorithm raytracing intersection

4
推荐指数
2
解决办法
1万
查看次数

取python中任意数量的列表的交集

假设我有一个完全相同的元素列表列表(int在本例中我将使用s)

[range(100)[::4], range(100)[::3], range(100)[::2], range(100)[::1]]
Run Code Online (Sandbox Code Playgroud)

采用这些列表的交集是一种很好的和/或有效的方法(所以你会获得每个列表中的每个元素)?对于以下示例:

[0, 12, 24, 36, 48, 60, 72, 84, 96]
Run Code Online (Sandbox Code Playgroud)

python algorithm intersection list

4
推荐指数
1
解决办法
935
查看次数

交叉或解决

考虑以下 :

daList = {{541, 0.0593368}, {550, 0.298352}, {560, 0.72619}, {570,0.734982}, 
          {580, 1.46149}, {590, 2.31119}, {600, 3.31509}}
Run Code Online (Sandbox Code Playgroud)

每个子列表代表{x,y}坐标.

我需要找到Y等于1的x值.用眼睛大约575.

ListPlot[daList, 
        Joined -> True, 
        Epilog ->{Thick, Line[{{0, 1}, {600, 1}}]}]
Run Code Online (Sandbox Code Playgroud)

+来自PPT的红色部分的帮助来说明问题:

在此输入图像描述

可以插值直到找到1,但我想知道Mathematica中是否存在这个函数.

无论是计算.找到y = 1的X.或者可以是在x轴上报告线交点x坐标的图形.

wolfram-mathematica intersection solution

4
推荐指数
3
解决办法
3613
查看次数