How to specify positions in a matrix by an array?

If I have an array of sets of points such as

pts = {{2,4},{1,3},{5,7}}

Is there any super short command to use those pairs to output their respective elements in a matrix in one felt swoop without loops?

Also, is there a way to output elements of an array corresponding to just the first or just the second element in all pairs?
so given an array

array = {1,2,3,4,5,6,7,8}

output only

{2,1,5}

corresponding to the first element in each pair in pts

=================

2

 

Take a look at Part, Extract, Span and friends. array[[pts[[All, 1]]]].
– Kuba
Jun 17 ’15 at 17:00

  

 

@Kuba, perfect, thank you!
– Solarmew
Jun 17 ’15 at 17:11

  

 

@Kuba ups! Haven’t read your comment in time. Sorry
– Dr. belisarius
Jun 17 ’15 at 17:25

  

 

@belisarius I don’t think you should be, why? 🙂
– Kuba
Jun 17 ’15 at 17:32

  

 

@Kuba I used Extract in my answer and you suggested that a pair of minuts before in your comment. Nothing to worry about, I guess!
– Dr. belisarius
Jun 17 ’15 at 17:48

=================

1 Answer
1

=================

SeedRandom[42];
pts = {{2, 4}, {1, 3}, {5, 7}};
a = RandomInteger[{1, 10}, {7, 7}]
Extract[a, pts]
(* {2, 9, 10} *)

Grid[a, Background -> {None, None, Thread[pts -> Red]}]

  

 

great! thank you!
– Solarmew
Jun 17 ’15 at 17:02

  

 

Haha, very fancy XD
– Solarmew
Jun 17 ’15 at 17:12