0
$\begingroup$

I want to exchange the two data points in a list, like {0.8,0.4} into {0.4,0.8}.

So how can make it easier without doing it manually?

$\endgroup$
1
  • 4
    $\begingroup$ Reverse @ {0.8, 0.4} $\endgroup$
    – eldo
    Commented Sep 12, 2023 at 15:59

1 Answer 1

5
$\begingroup$

All these will take {0.8,0.4} and transform it into {0.4,0.8}

Reverse[{0.8,0.4}]
(* {0.4,0.8} *)

{0.8,0.4}/.{x_,y_}->{y,x}
(* {0.4,0.8} *)

RotateLeft@{0.8,0.4}
(* {0.4,0.8} *)

RotateRight@{0.8,0.4}
(* {0.4,0.8} *)

Part[{0.8,0.4}, {2,1}]
(* {0.4,0.8} *)

Sort[{0.8,0.4}]
(* {0.4,0.8} *)

Dot[{0.8,0.4},{{0,1},{1,0}}]
(* {0.4,0.8} *)

ReflectionTransform[{1, -1}]@{0.8,0.4}
(* {0.4,0.8} *)
$\endgroup$
1
  • $\begingroup$ What am I missing? $\endgroup$
    – rhermans
    Commented Sep 12, 2023 at 16:14

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