It is a elemental question maybe,but I am confusing still.If I have a 1-dimension list list
a = Range[5]
(* {1, 2, 3, 4, 5} *)
So I can do this to get the first and last element:
a[[{1, -1}]]
(* {1, 5} *)
But when I have a matrix mat
,why I cannot do this with same method?
mat = Partition[Range[12], 4];
mat[[{{1, 1}, {-1, -1}}]]
This expression will put some error information.
Question
- Did I make any grammatical mistakes?
- Can we use any elegant method to get this two elements?
mat[[1,1]]
andmat[[-1,-1]]
. Or to use same syntax as 1D example, can Flatten the matrix first. $\endgroup$Extract[mat,{{1,1},{-1,-1}}]={c,d}
.This is my purpose actually. $\endgroup$[[x,y]]
much easier and more common with other languages (Matlab, etc...) than having to call functions to do it $\endgroup$