Previous Up Next

6.44.5  Getting the parts of a matrix

Accessing parts of a matrix: [] at

The rows of a matrix are the elements of a list, and can be accessed with indices using the postfix […] or the prefix at (see Section 6.39.6).


Example.
Input:

A:= [[1,2,6], [3,4,8], [1,0,1]]

then:

A[0]

or:

at(A,0)

Output:


1,2,6


To extract a column of a matrix, you can first turn the columns into rows with transpose (see Section 6.47.1), then extract the row as above.

Example.
Input:

tran(A)[1]

or:

at(tran(A),1)

Output:


2,4,0


Individual elements are simply elements of the rows.


Example.
Input:

A[0][1]

Output:

2

This can be abbreviated by listing the row and column separated by a comma.
Input:

A[0,1]

or:

at(A,[0,1])

Output:

2

The indexing begins with 0; you can have the indices start with 1 by enclosing them in double brackets.
Input:

A[[1,2]]

Output:

2


You can use a range (see Section 6.37.1) of indices to get submatrices.


Examples.


Recall that An index of -1 returns the last element of a list, an index of -2 the second to last element, etc.


Examples.

Extracting rows or columns of a matrix (Maple compatibility): row col

The row (respectively col) command extracts one or several rows (respectively columns) of a matrix.


Examples.



Examples.

Extracting a sub-matrix of a matrix (TI compatibility): subMat

The subMat command finds submatrices of a matrix.


Example.
Input:

A:=[[3,4,5],[1,2,6]]

Output:



345
126



Previous Up Next