- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 2 个带有网格像素坐标的数组。
[402, 401, 356, 355, 356, 355, 356, 386, 354, 355, 356, 386, 354, 355, 386, 354, 287, 288, 289, 290, 291, 292, 287, 288, 290, 291, 292, 293, 292, 293, 294, 295, 293, 294, 295, 296, 294, 295, 296, 146, 145, 146, 167, 168, 162, 163, 164, 165, 166, 167, 168, 169, 170, 160, 161, 162, 165, 166, 167, 168, 169, 170, 162, 163, 166, 167, 168, 169, 170, 163, 167, 168, 169, 170, 168, 169, 169, 170, 170, 310, 310, 311, 312, 313, 314, 315, 316, 317, 311, 312, 313, 314, 315, 316, 317, 311, 312, 313, 314, 315, 316, 311, 312, 313, 314, 315, 316, 311, 312, 313, 314, 274, 275, 275, 274, 275, 274, 275, 273, 274, 275, 274, 275, 274, 272, 273, 272, 273, 272, 273, 272, 273, 272, 273, 271, 272, 271]
[242, 243, 257, 258, 258, 259, 259, 259, 260, 260, 260, 260, 261, 261, 261, 262, 284, 284, 284, 284, 284, 284, 285, 285, 285, 285, 285, 285, 286, 286, 286, 286, 287, 287, 287, 287, 288, 288, 288, 326, 327, 327, 337, 337, 338, 338, 338, 338, 338, 338, 338, 338, 338, 339, 339, 339, 339, 339, 339, 339, 339, 339, 340, 340, 340, 340, 340, 340, 340, 341, 341, 341, 341, 341, 342, 342, 343, 343, 344, 382, 383, 383, 383, 383, 383, 383, 383, 383, 384, 384, 384, 384, 384, 384, 384, 385, 385, 385, 385, 385, 385, 386, 386, 386, 386, 386, 386, 387, 387, 387, 387, 416, 416, 417, 418, 418, 419, 419, 420, 420, 420, 421, 423, 427, 428, 428, 429, 429, 430, 430, 431, 431, 432, 432, 433, 433, 434]
数据中大约有 8 个数字相互连接的位置。主要问题是如何找到这些点。我们想为每个点创建一个数组,其中包含数字。我认为这是一个简单的问题,但仍然没有找到如何编程的方法。
我尝试过使用 while 和 for 循环,但最终一无所获。做到这一点的最佳方法是什么?
最佳答案
嗯,我不确定为什么要提供额外的位置,但它们看起来与您的列表相匹配。我得到了175个名额! (当然 2-4、3-4、3-5、4-6、5-6 看起来与您的列表相匹配)。也许我正在使用不同的标准。以下是您可以随意破解的代码:
import numpy as np
a = np.array([[402, 401, 356, 355, 356, 355, 356, 386, 354, 355, 356, 386, 354, 355, 386, 354, 287, 288, 289, 290, 291, 292, 287, 288, 290, 291, 292, 293, 292, 293, 294, 295, 293, 294, 295, 296, 294, 295, 296, 146, 145, 146, 167, 168, 162, 163, 164, 165, 166, 167, 168, 169, 170, 160, 161, 162, 165, 166, 167, 168, 169, 170, 162, 163, 166, 167, 168, 169, 170, 163, 167, 168, 169, 170, 168, 169, 169, 170, 170, 310, 310, 311, 312, 313, 314, 315, 316, 317, 311, 312, 313, 314, 315, 316, 317, 311, 312, 313, 314, 315, 316, 311, 312, 313, 314, 315, 316, 311, 312, 313, 314, 274, 275, 275, 274, 275, 274, 275, 273, 274, 275, 274, 275, 274, 272, 273, 272, 273, 272, 273, 272, 273, 272, 273, 271, 272, 271],
[242, 243, 257, 258, 258, 259, 259, 259, 260, 260, 260, 260, 261, 261, 261, 262, 284, 284, 284, 284, 284, 284, 285, 285, 285, 285, 285, 285, 286, 286, 286, 286, 287, 287, 287, 287, 288, 288, 288, 326, 327, 327, 337, 337, 338, 338, 338, 338, 338, 338, 338, 338, 338, 339, 339, 339, 339, 339, 339, 339, 339, 339, 340, 340, 340, 340, 340, 340, 340, 341, 341, 341, 341, 341, 342, 342, 343, 343, 344, 382, 383, 383, 383, 383, 383, 383, 383, 383, 384, 384, 384, 384, 384, 384, 384, 385, 385, 385, 385, 385, 385, 386, 386, 386, 386, 386, 386, 387, 387, 387, 387, 416, 416, 417, 418, 418, 419, 419, 420, 420, 420, 421, 423, 427, 428, 428, 429, 429, 430, 430, 431, 431, 432, 432, 433, 433, 434]])
a = a.T
b = np.where(
(abs(np.subtract.outer(a[:,0], a[:,0])) <= 1.0) &
(abs(np.subtract.outer(a[:,1], a[:,1])) <= 1.0))
non_dup = np.where(b[0] < b[1]) # remove double count and 'self' overlaps
b = (b[0][non_dup], b[1][non_dup]) # remake slimmed down index
def find_group(group, start):
st_ix = np.where(b[0] == start)
for i in st_ix[0]:
dest = b[1][i]
group.add(start)
group.add(dest) # is this needed?
find_group(group, dest)
group_list = []
for i in b[0]: # NB this part is slow - it would be better to eliminate entries already dealt with - you can figure that out!
gp = set()
find_group(gp, i)
add_group = True
for old_gp in group_list:
if len(gp.intersection(old_gp)) > 0: # hopefully this has fixed it
old_gp = old_gp.union(gp)
add_group = False
break
if add_group:
group_list.append(gp)
xy_list = []
for gp in group_list:
xy_list.append(np.array([a[i] for i in gp]))
print(xy_list)
按上述方式进行编辑,以创建连续像素的 numpy 数组列表,如评论中所述。结果如下
[array([[402, 242],
[401, 243]]),
array([[356, 257],
[355, 258],
[356, 258],
[355, 259],
[356, 259],
[354, 260],
[355, 260],
[356, 260],
[354, 261],
[355, 261],
[354, 262]]),
array([[386, 260],
[386, 261],
[386, 259]]),
array([[287, 284],
[288, 284],
[289, 284],
[290, 284],
[291, 284],
[292, 284],
[287, 285],
[288, 285],
[290, 285],
[291, 285],
[292, 285],
[293, 285],
[292, 286],
[293, 286],
[294, 286],
[295, 286],
[293, 287],
[294, 287],
[295, 287],
[296, 287],
[294, 288],
[295, 288],
[296, 288]]),
array([[145, 327],
[146, 327],
[146, 326]]),
array([[167, 337],
[168, 337],
[166, 338],
[167, 338],
[168, 338],
[169, 338],
[170, 338],
[165, 339],
[166, 339],
[167, 339],
[168, 339],
[169, 339],
[170, 339],
[166, 340],
[167, 340],
[168, 340],
[169, 340],
[170, 340],
[167, 341],
[168, 341],
[169, 341],
[170, 341],
[168, 342],
[169, 342],
[169, 343],
[170, 343],
[170, 344]]),
array([[163, 341],
[160, 339],
[161, 339],
[162, 339],
[162, 340],
[163, 340]]),
array([[310, 382],
[310, 383],
[311, 383],
[312, 383],
[313, 383],
[314, 383],
[315, 383],
[316, 383],
[317, 383],
[311, 384],
[312, 384],
[313, 384],
[314, 384],
[315, 384],
[316, 384],
[317, 384],
[311, 385],
[312, 385],
[313, 385],
[314, 385],
[315, 385],
[316, 385],
[311, 386],
[312, 386],
[313, 386],
[314, 386],
[315, 386],
[316, 386],
[311, 387],
[312, 387],
[313, 387],
[314, 387]]),
array([[274, 416],
[275, 416],
[275, 417],
[274, 418],
[275, 418],
[274, 419],
[275, 419],
[273, 420],
[274, 420],
[275, 420],
[274, 421]]),
array([[272, 430],
[273, 430],
[272, 431],
[273, 431],
[272, 432],
[273, 432],
[271, 433],
[272, 433],
[271, 434],
[274, 427],
[273, 428],
[272, 429],
[273, 429]])]
关于python - 在python中查找np数组中的邻居,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29987855/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!