Post Reply 
List transpose using built-in?
10-28-2018, 11:46 PM (This post was last modified: 10-28-2018 11:50 PM by StephenG1CMZ.)
Post: #1
List transpose using built-in?
I have just added a list transpose implementation to my List API
Code:

 //TRY WITH ({{1,2,3},{4,5,6}})
EXPORT ListTRANSPOSE(LST)
//LIST TRANSPOSE
//WITH A 2D LST TRN(TRN(LST)) RETURNS ORIGINAL LIST
//A 1D LIST HAS NO PROPER TRANSPOSE AND MIGHT NOT RETURN USEFUL LST
//NOTE This is similar to the obvious builtin
//PRINT(mat2list(transpose(list2mat({{1,2,3},{4,5,6}}))));
//But the builtin unexpectedly flattens too 
BEGIN
LOCAL II,JJ;
LOCAL OUT:={};

FOR II FROM 1 TO SIZE(LST) DO
IF TYPE(LST(II))==TYPE({}) THEN //2D
FOR JJ FROM 1 TO SIZE(LST(II)) DO
OUT(JJ,II):=LST(II,JJ);
END;//FOR
ELSE 
//GUARD FLAT LIST//WHATS GOOD HERE? AN ERR MAY BE BETTER
//NEITHER OF THESE ARE IDEAL IN ALL CASES
OUT(II):=LST(II); 
//OUT(II):={LST(II)};
END;//IF
END;//FOR
 PRINT(mat2list(transpose(list2mat(LST)))); //why are these different?
 PRINT(OUT); //and which is correct?
RETURN OUT;
END;
But I was expecting the built-in sequence mat2list(transpose(list2mat)) to give the same results.
It is similar, but flatter than my implementation.
Am I wrong?

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
List transpose using built-in? - StephenG1CMZ - 10-28-2018 11:46 PM



User(s) browsing this thread: 1 Guest(s)