Matrix and Vector Entry Extraction
The methods for extracting entries from a Matrix or a Vector are similar.
For both Matrices and Vectors, a selection index, L, is one of an integer, a range of integers, or a list of integers and/or ranges of integers. The integer values in L can be negative.
In the following sections, V is a Vector and A is a Matrix.
Vector EntriesMatrix EntriesNegative IndicesErrors and the Degenerate Case
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk0">Vector Entries</Text-field>
Extract entries in V by using the command V[L]. The returned object is constructed from the specified selections in the following manner: if L is an integer, the returned object is a scalar; otherwise, it is a vector (even if the range or list provided in L indicates only one entry).
For example, to obtain a subvector consisting of the first, third, and fourth elements of a Vector V, use V[[1, 3, 4]] or V[[1, 3..4]], not V[1, 3, 4].
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk1">Matrix Entries</Text-field>
Extract entries in A by using the command A[L1, L2] where each Li is a selection index, L, as described above. The first index, L1, selects rows from A while the second index, L2, selects columns. The returned object is constructed from the intersection of the selected rows and columns.
If an Li is an integer, the corresponding dimension of the returned object is removed; otherwise, the corresponding dimension of the returned object is retained. For example, the result of A[1..1, 2..3] is a 1 x 2 Matrix, while the result of A[1, 2..3] is a row Vector, and that of A[1, 2] is a scalar.
If an Li is a list, the selected components (rows or columns) are returned in the same order given in Li. For example, A[[ 2, 1], 1..-1] is a new Matrix constructed from row 2 and row 1 of Matrix A, in that order.
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk2">Negative Indices</Text-field>
In all index specifications, negative indices are interpreted as follows: -1 selects the last row (column) or element, -2 selects the second last row (column) or element, -3 selects the third last row (column) or element, etc. For example, V[2..-1] returns the subvector consisting of all entries of V except the first.
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk3">Errors and the Degenerate Case</Text-field>
If Li is the range i..j with NiMvSSJpRzYiLCZJImpHRiUiIiJGKEYo and LUklbXJvd0c2JEkqcHJvdGVjdGVkR0YlL0krbW9kdWxlbmFtZUc2IkksVHlwZXNldHRpbmdHNiRGJUkoX3N5c2xpYkdGKDYpLUkjbW5HNiRGJS9GJ0YpNiNRIjFGKC1JI21vRzYkRiUvRidGKTYjUSUmbGU7RigtSSNtaUc2JEYlL0YnRik2I1EiaUYoRjMtRjo2I1EkZGltRigtRjQ2I1EnJnBsdXM7RihGLQ==, where dim is the corresponding dimension value, then the result is degenerate in the corresponding dimension (the dimension value in that component is 0). This is not an error. Otherwise, if Li is either an empty set of indices or it includes indices outside the appropriate dimension range, it is an error.
See AlsoLinearAlgebra Package IndexlistMatrixrangertable_indexingtype[MVIndex]Vector