Message Boards Message Boards

0
|
5151 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

[?] Turn a List into matrix coordinates?

Suppose I have m = {{1,2,3},{4,5,6},{7,8,9}} and another list q = {a,b}. I want to use q to extract element m[[a,b]]. So if a = b = 2, I'd get 5.

Certainly one can write m[[q[[1]],q[[2]]]], but is there a more compact expression? It seems that functionally I should be able to replace the head of q with something that would allow it to reference a part of list m. I've looked through the documentation and searched online but haven't found anything. Any suggestions would be appreciated.

POSTED BY: John Shonder
2 Replies

Thank you, exactly what I needed.

POSTED BY: John Shonder
Posted 5 years ago

Hi John,

Maybe Extract?

m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
q = {2, 2};
Extract[m, q]
(* 5 *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract