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$
1
  • $\begingroup$ You can also use patterns data //. {a_, b_, c__} :> {a, b} $\endgroup$ Dec 7, 2015 at 7:31

1 Answer 1

3
$\begingroup$

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

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

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.