list2mat and mat2list

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 554
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

list2mat and mat2list

Message par compsystems » jeu. avr. 29, 2021 2:53 pm

Hello

list2mat and mat2list are very important commands, since there are commands that operate differently when they are lists or matrices, in some it applies linear and matrix algorithm rules in other operations with a list of elements.

list2mat([9,8])> [[9,8]]
"reverse" command, converts a flat list
mat2list([[9,8]])> [9,8]

mat1: = list2mat([9,8]); > [[9,8]]
reverse command
list1: = mat2list (mat1); > [9,8]

mat2: = list2mat(list1); > [[9,8]]

It does not operate on arguments other than 2, it is very important to convert from list to matrix without having to specify the dimension, because if it is not specified, assume the conversion as a matrix of a row
list2mat([9,8,7]); > "list2mat ([9,8,7]) \ n Error: Bad argument value"
list2mat([9,8,7]); > [[9,8,7]]

specifying a conversion size
2 columns
list2mat([9, 8, 7], 2); > [[9,8], [7,0]]
1 column
list2mat([9, 8, 7], 1); > [[9], [8], [7]]
The argument 0, it is better to consider it as 1 row
list2mat([9,8,7], 0); > [[9,8,7]]

Finally flat conversion
mat2list([[9,8], [7,0]]); > [9,8,7,0]
ok, but with a second argument, it can be 0 to consider converting it to list list {{}} so as not to lose the original dimension
mat2list([[9,8], [7,0]], 0); > list[list[9,8], list[7,0]]

for arrays with variable columns, flatten on 1 list
mat2list ([[9,8,7], [6,0]]); > [9,8,7,6,0]
mat2list ([[9,8,7], [6,0]], 0); > list[list[9,8,7], list[6,0]]

Répondre