matrix#

swordfish.matrix(data: Any = None, *, type: DataType = None) Matrix#
swordfish.matrix(*, type: DataType = None, rows: int = 1, cols: int = 1, columns_capacity: int = 1, default: Any = None) Matrix

Creates a Swordfish Matrix from a Python object or initializes one with specified parameters.

There are two modes of initialization:

  • If data is provided, it converts the given Python object into a Matrix of the specified type.

  • If data is not provided, a new Matrix is created with the specified type, rows, cols, columns_capacity, and default value.

Parameters:
  • data (Any, optional) – The input data to initialize the Matrix. Defaults to None.

  • type (DataType, optional) – The data type for the Matrix. Defaults to None.

  • rows (int, optional) – The number of rows in the Matrix (used when data is None). Defaults to 1.

  • cols (int, optional) – The number of columns in the Matrix (used when data is None). Defaults to 1.

  • columns_capacity (int, optional) – The capacity for each column in the Matrix (used when data is None). Defaults to 1.

  • default (Any, optional) – The value used to fill the Matrix (used when data is None). Defaults to None.

Returns:

A Swordfish Matrix initialized based on the provided arguments.

Return type:

Matrix

Examples

Creating a Matrix from existing data:
>>> import swordfish as sf
>>> sf.matrix([1, 2, 3], type="INT")
Matrix(#0 #1 #2
-- -- --
1  2  3
, type=INT)
Creating an empty Matrix with specific type, rows, columns, and default value:
>>> sf.matrix(type="INT", rows=2, cols=2, columns_capacity=1, default=1)
Matrix(#0 #1
-- --
1  1
1  1
, type=INT)