resize/transform from matrix <-> vector

Messages in english

Modérateur : xcasadmin

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

resize/transform from matrix <-> vector

Message par compsystems » mer. avr. 10, 2019 9:06 pm

Hello BP.

The idea is to transform data types to vector or matrix, under the same command name.

makevector( set[1,2,1,3,4,4,5,5] ) > [1,2,3,4,5] // ok

makevector( poly1[-1,6,-11,6] ) > [-1,6,-11,6] // ok

# resize/transform from matrix to vector
makevector( [[9,8,7],[6,5,4],[3,2,1]] ) >
[9,8,7,6,5,4,3,2,1]


# resize from vector to matrix
matrix( 3, 3, [9,8,7,6,5,4,3,2,1]) >
[[9,8,7],[6,5,4],[3,2,1]]

matrix( 3, 4, [9,8,7,6,5,4,3,2,1]) >
[[9,8,7,6],[5,4,3,2],[1,0,0,0]]

matrix( 2, 4, [9,8,7,6,5,4,3,2,1]) >
[[9,8,7,6],[5,4,3,2]]

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: resize/transform from matrix <-> vector

Message par parisse » jeu. avr. 11, 2019 10:51 am

flatten will convert a matrix to a vector. The other commands already work unless I missed something.

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

Re: resize/transform from matrix <-> vector

Message par compsystems » ven. avr. 12, 2019 2:28 am

To makeMat if the first argument is an array, also make a dimension adjustment

makemat( [9,8,7,6,5,4,3,2,1], 3, 3) >
[[9,8,7],[6,5,4],[3,2,1]]

makemat(([[9,8,7],[6,5,4],[3,2,1]], [1,0], [[10,11],[12,13]]) >
[[9,8,7],[10,11,4],[12,13,1]]

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: resize/transform from matrix <-> vector

Message par parisse » ven. avr. 12, 2019 6:00 am

makemat expects a function, not an array, you already have matrix for that, as See also hints if you look at the help of makemat.

Répondre