Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: index of the minimum element of the array

by Not_a_Number (Prior)
on Jan 17, 2014 at 19:18 UTC ( [id://1071007]=note: print w/replies, xml ) Need Help??


in reply to index of the minimum element of the array

Use python:

a = [1, 2, -17, 99] min_idx = a.index(min(a))

Or ruby:

a = [1, 2, -17, 99] min_idx = a.index(a.min)

;-)

Update: Momentary confusion javascript/ruby. Corrected. Thanks, LanX.

This is the JS example I intended to supply:

var a = [1, 2, -17, 99]; var min_idx = a.indexOf(Math.min.apply(Math, a));

Replies are listed 'Best First'.
Re^2: index of the minimum element of the array
by dcmertens (Scribe) on Jan 18, 2014 at 03:55 UTC

    OP said "atm i am unable to patch perl on current pc, so a busrouitine for index would be the best solution for me." Suggesting another language seems like it is well outside the realm of possibility here.

    If we are going to suggest alternatives that involve installing things, why leave Perl? PDL provides a simple solution which is far more efficient than any of your solutions from other languages:

    use PDL; my $index = pdl(@data)->minimum_ind;
Re^2: index of the minimum element of the array
by LanX (Saint) on Jan 17, 2014 at 19:22 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1071007]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-28 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found