3
$\begingroup$

Suppose we have the following sample data

data = {{{10.4239, -0.0208131, 0.439032}, {10.379, -0.0194723, 
 0.737773}}, {{10.3581, 0.00106231, 0.84059}, {10.379, 0.0214038, 
 0.733933}}}

How can I create a new list containing only the first and second (or second and third) elements of the sublists? In other words how can I get this

data2 = {{{10.4239, -0.0208131}, {10.379, -0.0194723}}, {{10.3581,
        0.00106231, {10.379, 0.0214038}}}

Many thanks in advance!

$\endgroup$
  • $\begingroup$ You can also use patterns data //. {a_, b_, c__} :> {a, b} $\endgroup$ – Rorschach Dec 7 '15 at 7:31
3
$\begingroup$

data[[;; , ;; , 1 ;; 2]] gives the required answer. (Ref.)

$\endgroup$
  • $\begingroup$ Or data[[;; , ;; , {1,3}]] if I want the first and the third element, correct? $\endgroup$ – Vaggelis_Z Nov 24 '15 at 17:32
  • $\begingroup$ @Vaggelis_Z yup. $\endgroup$ – egwene sedai Nov 24 '15 at 17:32
  • $\begingroup$ Thank you very much for your quick response! $\endgroup$ – Vaggelis_Z Nov 24 '15 at 17:34
  • $\begingroup$ @Vaggelis_Z welcome! $\endgroup$ – egwene sedai Nov 24 '15 at 17:35
  • 1
    $\begingroup$ You can also use All in place of ;;. $\endgroup$ – evanb Nov 24 '15 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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