1 | initial version |
Hoping this answers the question.
Starting point
a list of lists:
sage: A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
two extra lists
sage: U = [100, 200, 300]
sage: V = [40, 50, 60]
Combined forms
sage: B = A + [U]
sage: B
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [100, 200, 300]]
sage: C = [a + [u] for a, u in zip(A, U)]
sage: C
[[1, 2, 3, 100], [4, 5, 6, 200], [7, 8, 9, 300]]
sage: a = SR.var('a')
sage: D = C + [V + [a]]
sage: D
[[1, 2, 3, 100], [4, 5, 6, 200], [7, 8, 9, 300], [40, 50, 60, a]]
Using matrices and vectors:
sage: A = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
sage: A
[1 2 3]
[4 5 6]
[7 8 9]
sage: U = vector([100, 200, 300])
sage: U
(100, 200, 300)
sage: B = A.augment(U)
sage: B
[ 1 2 3 100]
[ 4 5 6 200]
[ 7 8 9 300]
2 | No.2 Revision |
Hoping this answers the question.
Starting point
a list of lists:
sage: A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
two extra lists
sage: U = [100, 200, 300]
sage: V = [40, 50, 60]
Combined forms
sage: B = A + [U]
sage: B
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [100, 200, 300]]
sage: C = [a + [u] for a, u in zip(A, U)]
sage: C
[[1, 2, 3, 100], [4, 5, 6, 200], [7, 8, 9, 300]]
sage: a = SR.var('a')
sage: D = C + [V + [a]]
sage: D
[[1, 2, 3, 100], [4, 5, 6, 200], [7, 8, 9, 300], [40, 50, 60, a]]
Using matrices and vectors:
sage: A = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
sage: A
[1 2 3]
[4 5 6]
[7 8 9]
sage: U = vector([100, 200, 300])
sage: U
(100, 200, 300)
sage: B = A.augment(U)
sage: B
[ 1 2 3 100]
[ 4 5 6 200]
[ 7 8 9 300]
From a matrix to a list of vectors:
sage: B_rows = B.rows()
sage: B_rows
[(1, 2, 3, 100), (4, 5, 6, 200), (7, 8, 9, 300)]
From a matrix to a list of lists:
sage: B_list_of_lists = [list(row) for row in B]
sage: B_list_of_lists
[[1, 2, 3, 100], [4, 5, 6, 200], [7, 8, 9, 300]]
3 | No.3 Revision |
Hoping this answers the question.
Starting point
a list of lists:
sage: A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
two extra lists
sage: U = [100, 200, 300]
sage: V = [40, 50, 60]
Combined forms
sage: B = A + [U]
sage: B
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [100, 200, 300]]
sage: C = [a + [u] for a, u in zip(A, U)]
sage: C
[[1, 2, 3, 100], [4, 5, 6, 200], [7, 8, 9, 300]]
sage: a = SR.var('a')
sage: D = C + [V + [a]]
sage: D
[[1, 2, 3, 100], [4, 5, 6, 200], [7, 8, 9, 300], [40, 50, 60, a]]
Using matrices and vectors:
sage: A = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
sage: A
[1 2 3]
[4 5 6]
[7 8 9]
sage: U = vector([100, 200, 300])
sage: U
(100, 200, 300)
sage: B = matrix(A.rows() + [U])
sage: B
[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[100 200 300]
sage: C = A.augment(U)
sage: B
C
[ 1 2 3 100]
[ 4 5 6 200]
[ 7 8 9 300]
From a matrix to a list of vectors:
sage: B_rows = B.rows()
sage: B_rows
C_rows = C.rows()
sage: C_rows
[(1, 2, 3, 100), (4, 5, 6, 200), (7, 8, 9, 300)]
From a matrix to a list of lists:
sage: B_list_of_lists C_list_of_lists = [list(row) for row in B]
sage: B_list_of_lists
C]
sage: C_list_of_lists
[[1, 2, 3, 100], [4, 5, 6, 200], [7, 8, 9, 300]]