Find first index of an item in an array in Julia

后端 未结 1 1829
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-17 08:41

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

相关标签:
1条回答
  • 2021-01-17 09:07

    There is 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).

    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.

    0 讨论(0)
提交回复
热议问题