Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: How to get the index of smallest whole number in an array?

by hda (Chaplain)
on Jul 01, 2018 at 09:59 UTC ( [id://1217684]=note: print w/replies, xml ) Need Help??

in reply to How to get the index of smallest whole number in an array?

Interesting problem and discussion. I have little to add to what has already been said, but wanted to note that a solution to the problem of finding the index of the minimum in an array is conveniently implemented in Perl Data Language (PDL) with the minimum_ind function.

From the manual:
Module PDL::Ufunc minimum_ind Signature: (a(n); indx [o] c()) Like minimum but returns the index rather than the value Output is set bad if all elements of the input are bad, otherwise +the bad flag is cleared for the output piddle.
So, in principle, assumming you already have an array @array you could do:
use PDL; my $piddle = pdl @array; my $index_minimum = minimum_ind $piddle; say $index_minimum;

You could try to reduce your problem so you can use a minimum_ind approach, for example, if you have negative numbers you could convert them to NaN or take abs and make them positive, whatever is important or relevant in your context.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-05-19 04:07 GMT
Find Nodes?
    Voting Booth?

    No recent polls found