0
|
7450 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

# Determine the position of the smallest positive number in a list

Posted 10 years ago
 How would I determine the position of the smallest positive number (including zero) from a list? A list of numbers, e.g. Range[-5, 5, 1] In this case, the list looks like this: {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5} And so the position is 6, which is the value I want returned. I found some complicated examples on Stack Exchange but have thus far been unable to apply them to this simpler case.
3 Replies
Sort By:
Posted 10 years ago
 Last[Last[Position[list, Min[Select[list, NonNegative]]]]] for just the value- thanks
Posted 10 years ago
 Position[list, Min[Select[list, NonNegative]]] 
Posted 10 years ago
 Nevermind, solved it. a = Range[-5, 5, 1] /. x_ /; x < 0.0 -> 999999999 b = Min[a] position = Last[Last /@ Position[a, _?(# == b &)]] 
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments