找到一个项目的第一个索引在朱莉娅的数组 [英] Find first index of an item in an array in Julia

查看:94
本文介绍了找到一个项目的第一个索引在朱莉娅的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是找到一些项目的第一个索引在朱莉娅数组?

What is the simplest way to find the first index of some item in an array in Julia?

推荐答案

调用发掘的是一个不错的选择。还有的FindFirst 更一般 FindNext中,它允许你重新启动你离开的地方。这两种的一个优点是,你并不需要分配一个输出数组,这样的表现会更好(如果你愿意)。

Calling findin is a great choice. There's also findfirst and more generally findnext, which allows you to restart where you left off. One advantage of these two is that you don't need to allocate an output array, so the performance will be better (if you care).

另外,请记住,(其它语言不同,你可以使用)Julia的循环速度快,并因此你可以自己总是写这样简单的功能。要明白我的意思,看看 FindNext中的实现(底座/ array.jl );没有什么神奇的有关它的,但你得到的表现,这只是因为如果你已经用C语言实现它,你会得到什么样的好。

Also, keep in mind that (unlike some other languages you may be used to) Julia's loops are fast, and as a consequence you can always write such simple functions yourself. To see what I mean, take a look at the implementation of findnext (in base/array.jl); there's nothing "fancy" about it, yet you get performance that is just as good as what you'd get if you had implemented it in C.

这篇关于找到一个项目的第一个索引在朱莉娅的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆