Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Putting a vector into part of a row of a matrix

So from the link given here- https://ask.sagemath.org/question/8366/editing-entries-of-matrix/

From the answer given, I see that to replace a row (say row 1) on a matrix by a list say List 1, I just do

[1,:]=vector(List1).

For example,

K=Matrix(QQ,6,8)

A priori, this is just the 0 matrix. Now writing,

K[1,:]=vector([1,1,1,1,1,1,1,1])

will replace my first row of my 6 x 8 matrix with the entries all 1's. However, what if I just want to replace say row 1 but the last 6 entries so I will have [0,0,1,1,1,1,1,1]. Of course, I can just type out K[1,:]=vector([0,0,1,1,1,1,1,1]) but this is not viable for larger matrices.

An example would be say my K=Matrix(QQ,40,80) and I have a list given by L1=[1,1,1,1]. Suppose I want to replace the row 1 with 40th-43rd entry being L1.

Method 1- Type out 76 zeros and do K[1,:]=vector(L1 with 76 zeros). This is not really ideal.

Method 2- Replace entry by entry. This is also not ideal if my L1 is say of length 20.

Is there a way to just say something like K[1,40-43]=vector([L1])?

Putting a vector into part of a row of a matrix

So from the link given here- https://ask.sagemath.org/question/8366/editing-entries-of-matrix/

From the answer given, I see that to replace a row (say row 1) on a matrix by a list say List 1, I just do

[1,:]=vector(List1).

K[1, :] = vector(List1)

For example,

K=Matrix(QQ,6,8)

K = Matrix(QQ, 6, 8)

A priori, this is just the 0 matrix. Now writing,

K[1,:]=vector([1,1,1,1,1,1,1,1])

writing

K[1, :] = vector([1, 1, 1, 1, 1, 1, 1, 1])

will replace my first row of my 6 x 8 matrix with the entries all 1's. 1's.

However, what if I just want to replace say row 1 but only the last 6 entries entries so I will have [0,0,1,1,1,1,1,1]. [0, 0, 1, 1, 1, 1, 1, 1]. Of course, I can just type out K[1,:]=vector([0,0,1,1,1,1,1,1]) out

K[1, :] = vector([0, 0, 1, 1, 1, 1, 1, 1])

but this is not viable for larger matrices.

An example would be say my K=Matrix(QQ,40,80) K = Matrix(QQ, 40, 80) and I have a list given by L1=[1,1,1,1]. L1 = [1, 1, 1, 1]. Suppose I want to replace the row 1 with 40th-43rd entry being L1. L1.

Method 1- Type out 76 zeros and do K[1,:]=vector(L1 K[1, :] = vector(L1 with 76 zeros). zeros). This is not really ideal.

Method 2- Replace entry by entry. This is also not ideal if my L1 L1 is say of length 20.

Is there a way to just say something like K[1,40-43]=vector([L1])?K[1, 40-43] = vector([L1])?