Question: convert every row of matrix to list

I'd like to convert  every row of matrix to list, but failed.  I want to use batch operations map(~) not for-loop.

data:=Matrix(3, 5, [[2, -6, 3, 0, 0], [5, -2, 4, 1, 2], [17, -4, 10, 20, 99]])

Matrix(3, 5, {(1, 1) = 2, (1, 2) = -6, (1, 3) = 3, (1, 4) = 0, (1, 5) = 0, (2, 1) = 5, (2, 2) = -2, (2, 3) = 4, (2, 4) = 1, (2, 5) = 2, (3, 1) = 17, (3, 2) = -4, (3, 3) = 10, (3, 4) = 20, (3, 5) = 99})

(2)

convert~(data,list)

Matrix(3, 5, {(1, 1) = [2], (1, 2) = [-6], (1, 3) = [3], (1, 4) = [0], (1, 5) = [0], (2, 1) = [5], (2, 2) = [-2], (2, 3) = [4], (2, 4) = [1], (2, 5) = [2], (3, 1) = [17], (3, 2) = [-4], (3, 3) = [10], (3, 4) = [20], (3, 5) = [99]})

(3)

convert(data,list)

[2, 5, 17, -6, -2, -4, 3, 4, 10, 0, 1, 20, 0, 2, 99]

(4)

The expected output is the following:

                        [2, -6, 3, 0, 0]
                        [5, -2, 4, 1, 2]
                      [17, -4, 10, 20, 99]

 

 

 

Download ss.mw

Please Wait...