热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

索引numpy索引,如带有2D点列表的数组-Indexingnumpyindiceslikearraywithlistof2Dpoints

Iamusingpython2.7我正在使用python2.7Ihaveanarrayofindicescreatedby我有一个由创建的索引数组idsn

I am using python 2.7

我正在使用python 2.7

I have an array of indices created by

我有一个由...创建的索引数组

ids=np.indices((20,20))

ids[0] is filled with all the vertical coordinates and ids1 is filled with all the horizontal coordinates ids has a shape of (2,20,20)

ids [0]填充所有垂直坐标,ids1填充所有水平坐标ids的形状为(2,20,20)

I have a boolean mask of shape (20,20)

我有一个布尔形状的面具(20,20)

I need to have a list of ids that correspond to the ones marked as true in the mask.

我需要有一个id列表,它们与掩码中标记为true的id相对应。

I am trying to do this by mid=ids[:,mask].T which gives me a list of this sort

我试图通过mid = ids [:,mask] .T来做这个,它给了我这种类型的列表

[2,17] [4,6] [1,19] [18,4]

[2,17] [4,6] [1,19] [18,4]

and so on. They are saved in an array called mid

等等。它们保存在一个名为mid的数组中

Then, I need all those coordinates in mid to find the values in another array. Meaning I need

然后,我需要mid中的所有坐标来查找另一个数组中的值。我需要的意思

anotherarray([2,17])

I have not managed to take the list of mid to use them in a fancy indexing way, can someone help me?

我没有设法将mid中的列表用于花哨的索引方式,有人可以帮助我吗?

I have

anotherarray[mid[0],mid[1]]

and it doesnt work. I also have

它不起作用。我也有

anotherarray[tuple(mid)]

and it doesn't work

它不起作用

Edit (read only if you care about context): I wanted to add context to show why I think I need the extra indices. Maybe I don't, that is what I want to fin out to make this efficient.

编辑(只有在关心上下文时才读):我想添加上下文来说明为什么我认为我需要额外的索引。也许我不这样做,这就是我想要的结果,以提高效率。

This is a registration problem, a ver simple one. I have two images. A reference and a floating as seen below. Reference to the left, and floating to the right.

这是一个注册问题,简单的问题。我有两张照片。参考和浮动如下所示。参考左边,并浮动到右边。

Reference image Floating image

The reference image and the floating image are in different coordinate spaces. I have points marked as you can see in the images. I find an affine transformation between each other.

参考图像和浮动图像位于不同的坐标空间中。我在图像中可以看到标记的点。我发现彼此之间有仿射变换。

The region delimited by the line is my region of interest. I send the coordinates of that region in the floating space to the reference space.

该线划定的区域是我感兴趣的区域。我将浮动空间中该区域的坐标发送到参考空间。

There in the reference space, I find what pixels are found inside the region and they become the mask array, containing the information of both in and outer pixels.

在参考空间中,我发现在区域内找到了哪些像素,它们成为掩模数组,包含内部像素和外部像素的信息。

But I only care about those inside, so I want only the indices of those pixels inside the mask in the reference space and save them using mid=ids[:,mask] .

但我只关心内部的那些,所以我只想要参考空间中掩码内的那些像素的索引,并使用mid = ids [:,mask]保存它们。

Once I have those points, I transform them back to the floating space, and in those new indices I need to look for the intensity. Those intensities are the ones who will be written back in the reference in their corresponding indices. That is why I think I need to have the indices of those points in both reference and floating space, and the intensities of the image. That other image is the anotherarray from which I want only the transformed masked pixels.

一旦我有了这些点,我就将它们转换回浮动空间,在那些新指数中我需要寻找强度。这些强度是那些将在相应指数中写回参考文献的强度。这就是为什么我认为我需要在参考和浮动空间中获得这些点的索引,以及图像的强度。另一个图像是另一个图像,我只想要转换的蒙版像素。

So there you go, that is the explanation if you care about it. Thank you for reading and answering.

那么你去吧,如果你关心它就是解释。感谢您阅读和回答。

1 个解决方案

#1


1  

A few tips: You can get mid directly from mask using np.argwhere(mask). Probably more convenient for your purpose is np.where which you can use like mi, mj = np.where(mask) and then anotherarray[mi, mj].

一些提示:您可以使用np.argwhere(mask)直接从掩码中获取。可能更方便你的目的是np.where你可以使用像mi,mj = np.where(掩码),然后anotherarray [mi,mj]。


推荐阅读
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 计算机存储系统的层次结构及其优势
    本文介绍了计算机存储系统的层次结构,包括高速缓存、主存储器和辅助存储器三个层次。通过分层存储数据可以提高程序的执行效率。计算机存储系统的层次结构将各种不同存储容量、存取速度和价格的存储器有机组合成整体,形成可寻址存储空间比主存储器空间大得多的存储整体。由于辅助存储器容量大、价格低,使得整体存储系统的平均价格降低。同时,高速缓存的存取速度可以和CPU的工作速度相匹配,进一步提高程序执行效率。 ... [详细]
  • 本文介绍了闭包的定义和运转机制,重点解释了闭包如何能够接触外部函数的作用域中的变量。通过词法作用域的查找规则,闭包可以访问外部函数的作用域。同时还提到了闭包的作用和影响。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • 本文介绍了Redis的基础数据结构string的应用场景,并以面试的形式进行问答讲解,帮助读者更好地理解和应用Redis。同时,描述了一位面试者的心理状态和面试官的行为。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
author-avatar
手机用户2502899537
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有