Hi -- I wonder if anyone call tell me why Position outputs { } (instead of {2}) in this example. Thank you in advance.
list = {1, 10}
pos = Nearest[list, 7]
Position[list, pos]
Thank you!
If you only want the first element returned from Flatten then you can use
Flatten
Position[list, First@pos]
Ah, I see. 10 is in the list but {10} is not. Is there a better way to fix it besides the following?
list = {{1}, {10}}
pos = Flatten[Nearest[list, 7]]
Flatten[Position[list, pos]]
Because pos, which is equal to the list {10} is not in the list list.
pos
{10}
list