4
$\begingroup$

Suppose I have a nested list of the form:

test = {{1,2},{2,3},{1,6},{2,5},{2,2},{1,7},{1,4}}

How do I find the position of the list in which the elements are equal, which in this example is {5} -> position of {2,2}

Update 1

Suppose my nested list is:

{{0.99258878, 0.99258845}, {0.97357684, 0.97357712}, {0.95312105, 
  0.95386979}, {0.93345214, 0.93345301}, {0.91233411, 0.91233415}, {0.89050811, 
  0.89050798}, {0.86800801, 0.86800954}, {0.84486887, 0.84486964}, {0.82114124, 
  0.82114187}, {0.79689807, 0.79689753}}

I wish to find the position for which elements are equal with a 6 significant digit accuracy, like the position of the list {0.99258878, 0.99258845}

$\endgroup$
5
  • $\begingroup$ Position[test, {a_, a_}] $\endgroup$
    – Syed
    Mar 22 at 7:53
  • $\begingroup$ @Syed thank you, suppose I have a very big nested list in which some elements are approximately equal, say a list like {1.5,1.4999} or {1.88812,1.88913} how to include the positions of these as well? How to state the level of accuracy? $\endgroup$
    – codebpr
    Mar 22 at 7:58
  • $\begingroup$ Please update the post and present a list with real numbers and the accuracy required. This is new information. $\endgroup$
    – Syed
    Mar 22 at 8:01
  • $\begingroup$ @Syed I have updated my question! $\endgroup$
    – codebpr
    Mar 22 at 8:20
  • 2
    $\begingroup$ A variation on the method given below by Syed: Round[lst,10^-6]//MapApply[Subtract]//Position[0] $\endgroup$
    – user1066
    Mar 23 at 18:39

1 Answer 1

6
$\begingroup$

Using Round with the second argument:

test = {{0.99258878, 0.99258845}, {0.97357684, 
   0.97357712}, {0.95312105, 0.95386979}, {0.93345214, 
   0.93345301}, {0.91233411, 0.91233415}, {0.89050811, 
   0.89050798}, {0.86800801, 0.86800954}, {0.84486887, 
   0.84486964}, {0.82114124, 0.82114187}, {0.79689807, 0.79689753}}

Position[test, _?(SameQ @@ (Round[#, 10^-6]) &)]

{{2}, {5}, {6}, {10}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.