matrix

Syntax

matrix(dataType, rows, cols, [columnsCapacity], [defaultValue])

or

matrix(X1, [X2], …)

Arguments

For the first case:

  • dataType is the data type of the elements in the matrix.

  • rows is the number of rows.

  • cols is the number of cols.

  • columnsCapacity is the amount of memory (in terms of the number of columns) allocated to the matrix. When the number of columns exceeds columnsCapacity, the system will first allocate memory of 1.2~2 times of capacity, copy the data to the new memory space, and release the original memory.

  • defaultValue is the default value for the elements of the matrix. Without specifying defaultValue, all elements in the matrix are 0s for integers/doubles and NULLs for symbols.

For the second case, X1, X2, … can be hybrid data objects including vector, matrix, table, tuple of vectors and their combination.

Details

Generate a matrix.

Examples

$ x=matrix(`INT,3,2, ,1);
$ x;

#0

#1

1

1

1

1

1

1

$ s=matrix(`SYMBOL,2,2, ,`T);
$ s;

#0

#1

T

T

T

T

$ matrix(table(1 2 3 as id, 4 5 6 as value));

#0

#1

1

4

2

5

3

6

$ matrix([1 2 3, 4 5 6]);

#0

#1

1

4

2

5

3

6

$ matrix([1 2 3, 4 5 6], 7 8 9, table(0.5 0.6 0.7 as id), 1..9$3:3);

#0

#1

#2

#3

#4

#5

#6

1

4

7

0.5

1

4

7

2

5

8

0.6

2

5

8

3

6

9

0.7

3

6

9

Related functions: array and dict