Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.9K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Why doesn't Position work in this example?

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]

POSTED BY: Fernando Benadon
4 Replies

Thank you!

POSTED BY: Fernando Benadon

If you only want the first element returned from Flatten then you can use

Position[list, First@pos]
POSTED BY: David Reiss

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]]

POSTED BY: Fernando Benadon

Because pos, which is equal to the list {10} is not in the list list.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard