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:
It is similar, but flatter than my implementation. Am I wrong? Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
10-29-2018, 01:19 AM
Post: #2
|
|||
|
|||
RE: List transpose using built-in?
(10-28-2018 11:46 PM)StephenG1CMZ Wrote: I was expecting the built-in sequence mat2list(transpose(list2mat)) to give the same results. I think matrix is already a 2D list (list of list). a := [[1, 2, 3], [4,5,6]] a[0] ==> [1, 2, 3] mat2list(...) just return coefficient of the matrix, thus flattened it. mat2list(a) ==> [1, 2, 3, 4, 5, 6] The name is misleading. mat2list is more like mat2vec. |
|||
10-31-2018, 12:59 PM
Post: #3
|
|||
|
|||
RE: List transpose using built-in?
(10-28-2018 11:46 PM)StephenG1CMZ Wrote: I was expecting the built-in sequence mat2list(transpose(list2mat)) to give the same results. Here is another way to transpose a list of lists using built-in commands: MAKELIST(mat2list(col(LST,I)),I,1,colDim(LST)) it should be faster than the double FOR loop. Note: it seems, at least with the latest Prime beta firmware, that the column index start value is different between the Virtual Prime and the real Prime/Android Prime. On the Windows Virtual Prime, you would need to do: MAKELIST(mat2list(col(LST,I)),I,0,colDim(LST)-1) I've reported this to calcbeta. |
|||
10-31-2018, 01:04 PM
(This post was last modified: 10-31-2018 01:15 PM by Tim Wessman.)
Post: #4
|
|||
|
|||
RE: List transpose using built-in?
Were you playing around with unsupported, non-documented, please don't use, CAS python syntax at all? That changes the index for CAS commands system wide... :/ (not a bug but by "design")
TW Although I work for HP, the views and opinions I post here are my own. |
|||
10-31-2018, 01:38 PM
(This post was last modified: 10-31-2018 01:58 PM by Didier Lachieze.)
Post: #5
|
|||
|
|||
RE: List transpose using built-in?
Well, I agree that col(list, integer) may be extending a bit the definition of col(matrix, integer), but using a matrix instead of a list gives the same results:
EDIT: interestingly I restarted the CAS with 'restart' and now I get the expected [1 4] result on the Windows Virtual calc. However I didn't intentionally tried the Python syntax as far as I remember, or not in the recent past. Anyway, this is quite dangerous to have this kind of system wide setting being silently changed and being persistent with no user warning. |
|||
10-31-2018, 01:55 PM
(This post was last modified: 10-31-2018 02:03 PM by compsystems.)
Post: #6
|
|||
|
|||
RE: List transpose using built-in?
I think it has to do with the internal variable, variable index:=1 or index:=0
Xcas mode index:=0; col([[1,2,3],[4,5,6]],1) returns [2 5] index:=1; col([[1,2,3],[4,5,6]],1) returns [1 4] other variables that are not documented or do not appear in the catalog. http://www.hpmuseum.org/forum/thread-11554.html |
|||
11-01-2018, 08:08 AM
(This post was last modified: 11-01-2018 08:12 AM by StephenG1CMZ.)
Post: #7
|
|||
|
|||
RE: List transpose using built-in?
Thanks everyone.
One advantage of simple nested FOR loops... They may be slower, but the code is more portable as your indexing is under your control. I did use never-use-Python in my Savage Benchmark program, but not in List. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)