使用NumPy查找条件为True的范围(Find span where condition is True using NumPy)
想象一下,我有一个numpy数组,我需要找到条件为True的跨度/范围。 例如,我有以下数组,其中我试图找到项大于1的跨度:
[0, 0, 0, 2, 2, 0, 2, 2, 2, 0]
我需要找到索引(开始,停止):
(3, 5) (6, 9)
我能够实现的最快的事情是制作一个布尔数组:
truth = data > threshold
然后使用
numpy.argmin
和numpy.argmax
循环遍历数组以查找开始和结束位置。pos = 0 truth = container[RATIO,:] > threshold while pos < len(truth): start = numpy.argmax(truth[pos:]) + pos + offset end = numpy.argmin(truth[start:]) + start + offset if not truth[start]:#nothing more break if start == end:#goes to the end end = len(truth) pos = end
但是对于阵列中的数十亿个位置来说这已经太慢了,而且我发现的跨度通常只是连续几个位置。 有谁知道更快找到这些跨度的方法?
Imagine I have a numpy array and I need to find the spans/ranges where that condition is True. For example, I have the following array in which I'm trying to find spans where items are greater than 1:
[0, 0, 0, 2, 2, 0, 2, 2, 2, 0]
I would need to find indices (start, stop):
(3, 5) (6, 9)
The fastest thing I've been able to implement is making a boolean array of:
truth = data > threshold
and then looping through the array using
numpy.argmin
andnumpy.argmax
to find start and end positions.pos = 0 truth = container[RATIO,:] > threshold while pos < len(truth): start = numpy.argmax(truth[pos:]) + pos + offset end = numpy.argmin(truth[start:]) + start + offset if not truth[start]:#nothing more break if start == end:#goes to the end end = len(truth) pos = end
But this has been too slow for the billions of positions in my arrays and the fact that the spans I'm finding are usually just a few positions in a row. Does anyone know a faster way to find these spans?
原文:https://stackoverflow.com/questions/17150974
最满意答案
您无法在场景编辑器中执行此操作。 你可能根本不应该这样做。 您必须实现自己的序列化代码(以便
SCNScene
加载正常工作)。 并且所有用于搜索节点的方法(按名称,命中测试,在卷中)都会返回SCNNode
,因此您将永远投射结果。对于Apple开发人员来说,
SCNScene
并不意味着是子类,我认为它扩展到了SCNNode
。 写一个扩展名。看到:
You can't do it in the scene editor. And you probably shouldn't do it at all. You'll have to implement your own serialization code (so that
SCNScene
loading works correctly). And all of the methods for searching nodes (by name, hit test, within a volume) returnSCNNode
, so you'll be forever casting your results.Per Apple developers,
SCNScene
is not meant to be subclassed, and I think that extends toSCNNode
. Write an extension instead.See:
相关问答
更多-
您可以使用UTF8的强大功能和• char var text = new Kinetic.Text({ fill : "black", text : "• item 1\n• item 2" }); 演示: http : //jsfiddle.net/lavrton/2QeM5/1/ 更新:您也可以使用html进行图像转换,然后您可以将图像添加到画布。 请参阅: http : //jsfiddle.net/lavrton/sDp6C/ You may use power of UTF8 w ...
-
我不相信XML Serializer会为集合调用set访问器。 相反,它只会调用它从get访问器检索的集合实例的Add方法。 我相信您需要让您的集合类型覆盖Add和Remove方法等,以修改集合,然后将修改后的集合序列化回用户属性。 I don't believe the XML Serializer will ever call the set accessor for a collection. Instead, it will just call the Add method of the colle ...
-
在网格中实现多选时,您需要考虑几个问题。 值不是单个值而是值数组,因此您需要实现某种方式将其显示为(例如)逗号分隔值。 如果你使用data-bind="value:' + options.field + '"那么这将覆盖value: [ "Classical" ] 。 实际上后者没有意义,因为你想要的是最初显示已经存储在Grid DataSource中的值 There are a couple of questions that you need to consider when implementing ...
-
在AlloYUI Diagram Builder中更改节点的默认编辑器(Change default editor for node in AlloYUI Diagram Builder)[2023-01-22]
感谢罗伯特弗兰普顿,他在谷歌小组中解答了我的问题,这样做的方法是: model.push({ attributeName: 'customAttr', name: 'Custom Attribute', editor: new Y.DateCellEditor() }); 您必须在构造函数之前添加“new”来创建Y.DateCellEditor对象的新实例。 Thanks to Robert Frampton, who anwered my question in google gro ... -
自定义JComboBox编辑器(Custom JComboBox editor)[2021-12-25]
我能看到的第一组问题是,您在NewComboEditor定义了一个JTextField和JButton ,但也定义了一个textPanel ,它包含所有这些东西。 但是,不是使用textPane上的textPane ,而是使用新创建的组件(在NewComboEditor ),而不是......实际上,我甚至不确定这是如何工作的,因为您从不初始化这些组件(在NewComboEditor ) ,所以应该有一个NullPointerException ... 如果这没有足够的问题, JTextField和JBut ... -
经过很多痛苦之后,答案就是没有。 您无法在笔尖中显示自定义字体。 你可以设置它们虽然有点帮助。 我希望在某些时候苹果会解决这个问题。 After a lot of pain the answer is simply no. You can not display custom fonts in the nib. You can set them though which is a little help. I hope at some point apple will fix this.
-
无法访问由Umbraco自定义网格编辑器生成的JSON节点(Trouble accessing JSON node generated by Umbraco custom grid editor)[2023-09-28]
没有人评论,但我想列举一个答案,以防万一它有助于某人。 正如我所料,我只是过于复杂(当然,愚蠢)。 您访问Umbraco属性的方式是通过“mediaItem = Umbraco.Media(id)”,然后是“linkText = @ mediaItem.GetPropertyValue(”linkText)“。 以下是最终(工作)渲染器的外观: @inherits Umbraco.Web.Mvc.UmbracoViewPage您无法在场景编辑器中执行此操作。 你可能根本不应该这样做。 您必须实现自己的序列化代码(以便SCNScene加载正常工作)。 并且所有用于搜索节点的方法(按名称,命中测试,在卷中)都会返回SCNNode ,因此您将永远投射结果。 对于Apple开发人员来说, SCNScene并不意味着是子类,我认为它扩展到了SCNNode 。 写一个扩展名。 看到: 麻烦继承SCNScene 子类化SCNNode 子类化SCNScene和SceneKit编辑器 You can't do it in the scene ed ...在场景编辑器的下半部分,您可以打开动作编辑器。 选择节点后,您将能够在其时间轴中拖放操作。 您可以在“ SceneKit增强功能 ”会话中找到动作编辑器的演示。 In the lower part of the scene editor you can open the action editor. After selecting an node you'll be able to drag and drop actions in its timeline. You can find a demo of t ...它似乎只是XamPropertyGrid中的一个错误,您需要做的就是更新到Version 2015.2 It seems that it was just a bug in XamPropertyGrid, all you need to do is to update to Version 2015.2相关文章
更多- Hadoop “Failed to set setXIncludeAware(true) for parser” 错误
- 微信支付http://www.cnblogs.com/True_to_me/p/3565039.html
- 关于不定条件写法的问题
- could not find system property or JNDI
- 基于Solr的HBase多条件查询测试
- Solr的HBase多条件查询
- solr实现满足指定距离范围条件的搜索
- (转载)solr实现满足指定距离范围条件的搜索
- 科技英语翻译480句 (四) 条件
- 关于多线程问题,signalAll,await问题
最新问答
更多- 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
- Java中的不可变类(Immutable class in Java)
- 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
- linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
- Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
- 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
- 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
- Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
- EXCEL VBA 基础教程下载
- RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
- 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
- JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
- mysql 关于分组查询、时间条件查询
- 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
- Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
- 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
- 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
- 使用前端框架带来哪些好处,相对于使用jquery
- Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
- 高考完可以去做些什么?注意什么?
- 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
- 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
- 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
- R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
- Allauth不会保存其他字段(Allauth will not save additional fields)
- python中使用sys模块中sys.exit()好像不能退出?
- 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
- 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
- sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
- 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)