1
$\begingroup$

How can the following list

list = {{0.1,{l->1,n->2}},{0.12,{l->1.1,n->2.1}},{0.5,{l->0.8,n->9}}};

be first organized as

list = {{0.1,1,2},{0.12,1.1,2.1},{0.5,0.8,9}};

and then remove points that are close (by metric distance), such that the result will be

list = {{0.1,1,2},{0.5,0.8,9}};
$\endgroup$
1
  • $\begingroup$ list[[All, 2]] = Values@list[[All, 2]];Partition[Flatten@list, 3] $\endgroup$ Commented Aug 24, 2018 at 15:57

1 Answer 1

1
$\begingroup$

Try the following with your definition of list:

flattened = MapAt[Apply[Sequence]@*Values, list, {All, 2}]

(* Out: {{0.1, 1, 2}, {0.12, 1.1, 2.1}, {0.5, 0.8, 9}} *)

Then remove "close" values; adjust the rounding threshold to suit:

filtered = DeleteDuplicatesBy[flattened, Round[Norm[#], 1] &]

(* Out: {{0.1, 1, 2}, {0.5, 0.8, 9}} *)
$\endgroup$

Your Answer

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

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