Re: [julia-users] index of smallest / largest, a-la matlab

2,706 views
Skip to first unread message

Tim Holy

unread,
Dec 3, 2012, 3:55:22 PM12/3/12
to julia...@googlegroups.com
On Monday, December 03, 2012 11:00:58 AM Denny D wrote:
> Hello fellow Julia users! In matlab I can do
>
> [value,index]=max(x)
>
> value will be the greatest element in x, and index its index.

You want "findmax"

If you're coming from Matlab and just getting started with Julia, here's
another tidbit that may make you happy:

julia> findmax
Methods for generic function findmax
findmax(Array{T,N},) at array.jl:1311

Using that as a hint, open base/array.jl in a text editor and navigate to that
line #. You'll see it's implemented just using a for loop---there's no
"magic," it's all plain Julia, yet you're still getting great performance. So
if you don't find something, you can always roll your own. Of course, if it's
really useful, please consider contributing it.

--Tim

Elliot Saba

unread,
Dec 3, 2012, 3:55:54 PM12/3/12
to julia...@googlegroups.com
There's a pull request about adding this into julia here: https://github.com/JuliaLang/julia/pull/1655

Right now, the proposal is to call them indmin and indmax, respectively.  This hasn't been merged into julia yet, but if you're eager to try this out, you can use the slightly more complicated findmin and findmax functions:

findmax([1,2,1,2,1,2,3,1,2,1,2,1])

returns (3,7)



On Mon, Dec 3, 2012 at 11:00 AM, Denny D <brain...@gmail.com> wrote:
Hello fellow Julia users! In matlab I can do 

[value,index]=max(x)

value will be the greatest element in x, and index its index.

What is the equivalent way of doing this in Julia? As I understand max returns only value ... 

--
 
 

Reply all
Reply to author
Forward
0 new messages