1
$\begingroup$

How to get the first and second element in every last column from every row? eg. {{7,8}, {3,3}}

a = {
   {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}},
   {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}}
   };

I use a[[All,3]] get

{{7, 8, 9}, {3, 3, 3}}

A bit far from the requirements {{7,8}, {3,3}}

Any comments will be appreciate!

$\endgroup$
4
  • $\begingroup$ Map[Most,a[[All,3]]] or Most/@a[[All,3]] $\endgroup$
    – Bill
    Nov 19 '21 at 18:04
  • $\begingroup$ @Bill Thank you $\endgroup$
    – Ben
    Nov 19 '21 at 18:09
  • 5
    $\begingroup$ a[[All,-1,1;;2]] where "-1" is for the "last column" $\endgroup$
    – andre314
    Nov 19 '21 at 18:10
  • $\begingroup$ @andre314 Best answer! Thank you so much $\endgroup$
    – Ben
    Nov 19 '21 at 18:26

Browse other questions tagged or ask your own question.