slice#
- swordfish.function.slice()#
For slice(obj, index):
If obj is an array vector and
index is a scalar, it returns a vector indicating a column;
index is a vector, it returns an array vector of selected rows;
index is a pair, it returns an array vector of selected columns.
If obj is a matrix and
index is a scalar, it returns a vector indicating a column.
index is a vector or a pair, it returns a matrix of selected columns.
If obj is a table and
index is a scalar, it returns a dictionary indicating a row.
index is a vector or a pair, it returns a table of selected rows.
For slice(obj, rowIndex, [colIndex]):
If obj is an array vector and
rowIndex and colIndex are both scalars, it returns a vector indicating a column;
rowIndex is a scalar and colIndex is a pair (or vise versa), it returns an array vector of selected rows and columns;
rowIndex and colIndex are both pair, it returns an array vector of selected rows and columns.
If obj is a matrix and
rowIndex and colIndex are both scalars, it returns a scalar indicating the value of specified element of the matrix.
rowIndex is a scalar and colIndex is a pair (or vise versa), it returns a submatrix of selected rows and columns.
rowIndex and colIndex are both vectors or pairs, it returns a submatrix of selected rows and columns.
If obj is a table and
rowIndex and colIndex are both scalars, return a scalar indicating the value of specified element of the table.
rowIndex is a scalar and colIndex is a pair (or vise versa), it returns a table of selected rows and columns.
rowIndex and colIndex are both vectors or pairs, it returns a table of selected rows and columns.
Note
To get a particular row or column from a table, consider using function col or row.
When index, rowIndex or colIndex specifies the index range of an array vector or a matrix, if the values are not within [0, size(X)-1], the corresponding results are null values.
- Parameters:
obj (Constant) – Can be an array vector, a matrix or a table.
index (Union[Alias[Literal["rowIndex"]], Constant]) – Can be scalar/vector/pair indicating the row index. If index, rowIndex is a pair, it indicates the range of index which is left-closed and right-open.
colIndex (Constant, optional) – Can be scalar/vector/pair indicating the column index, by default DFLT. If colIndex is a pair, it indicates the range of index which is left-closed and right-open.