ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 15 Jan 2015 01:46:04 -0600Transpose of a column vectorhttps://ask.sagemath.org/question/25503/transpose-of-a-column-vector/Hi, I've got a column vector and I need to transpose it. But when i do:
`v=v.column()` it says *column() takes at least 1 positional argument (0 given)*
I've also tried doing ` v=Matrix([[1, 0, 0],[0, 1, 0], [0, 0, 1],])*v.column() ` which worked before but still doesn't work.
What is the problem here?
Thank youMon, 12 Jan 2015 12:04:10 -0600https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/Answer by SL for <p>Hi, I've got a column vector and I need to transpose it. But when i do:
<code>v=v.column()</code> it says <em>column() takes at least 1 positional argument (0 given)</em></p>
<p>I've also tried doing <code>v=Matrix([[1, 0, 0],[0, 1, 0], [0, 0, 1],])*v.column()</code> which worked before but still doesn't work.</p>
<p>What is the problem here?</p>
<p>Thank you</p>
https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?answer=25507#post-id-25507Note that you are trying to multiply a matrix by a list. Instead of using a list you should use another matrix.
Here's a way you can do it:
m = Matrix([[1, 0, 0],[0, 1, 0], [0, 0, 1]])
v = Matrix(3,1,[1,2,3])
m * v
Note several things
- m is the identity matrix, which you can create as `m = Matrix.identity(3)`
- the vector v is created by giving the dimensions, 3x1 in this case, and then giving a list of entries read along the rows from left to right and from top to bottom.Mon, 12 Jan 2015 16:42:17 -0600https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?answer=25507#post-id-25507Comment by SL for <p>Note that you are trying to multiply a matrix by a list. Instead of using a list you should use another matrix.
Here's a way you can do it: </p>
<pre><code>m = Matrix([[1, 0, 0],[0, 1, 0], [0, 0, 1]])
v = Matrix(3,1,[1,2,3])
m * v
</code></pre>
<p>Note several things</p>
<ul>
<li>m is the identity matrix, which you can create as <code>m = Matrix.identity(3)</code></li>
<li>the vector v is created by giving the dimensions, 3x1 in this case, and then giving a list of entries read along the rows from left to right and from top to bottom.</li>
</ul>
https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?comment=25526#post-id-25526Sage is written in the Python language. Python is an object-oriented programming language. You can think of an object as a way to store some data together with functions which operate on it an modify it. Everything in Python is an object; numbers are objects, lists are objects, etc. List is a very basic object which does not support many operations; you can index a list, you can join two lists, and you can do a few other things. Matrix is an object which supports many more operations. For example, you can compute the Jordan form of a matrix, you can multiply two matrices of appropriate sizes, etc. So a object of type Matrix corresponds better to the abstract mathematical notion of matrix than does an object of type list.Thu, 15 Jan 2015 01:46:04 -0600https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?comment=25526#post-id-25526Comment by Silvia for <p>Note that you are trying to multiply a matrix by a list. Instead of using a list you should use another matrix.
Here's a way you can do it: </p>
<pre><code>m = Matrix([[1, 0, 0],[0, 1, 0], [0, 0, 1]])
v = Matrix(3,1,[1,2,3])
m * v
</code></pre>
<p>Note several things</p>
<ul>
<li>m is the identity matrix, which you can create as <code>m = Matrix.identity(3)</code></li>
<li>the vector v is created by giving the dimensions, 3x1 in this case, and then giving a list of entries read along the rows from left to right and from top to bottom.</li>
</ul>
https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?comment=25519#post-id-25519Thank you for your reply.
May I ask you what is the difference between a list and a vector?Wed, 14 Jan 2015 03:41:20 -0600https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?comment=25519#post-id-25519Answer by slelievre for <p>Hi, I've got a column vector and I need to transpose it. But when i do:
<code>v=v.column()</code> it says <em>column() takes at least 1 positional argument (0 given)</em></p>
<p>I've also tried doing <code>v=Matrix([[1, 0, 0],[0, 1, 0], [0, 0, 1],])*v.column()</code> which worked before but still doesn't work.</p>
<p>What is the problem here?</p>
<p>Thank you</p>
https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?answer=25504#post-id-255041. Maybe you don't need to transpose your column vector. If `A` is a matrix and `v` is a vector, then `A * v` will use `v` as a column vector, and `v * A` will use `v` as a row vector.
2. If you want to make `v` a row vector, you can do `v.row()`.
3. the `column` method is for extracting a column of a matrix. You need to specify the index of the column (from 0 to nrows - 1).
Illustration:
sage: m = Matrix([[1, 1, 0],[0, 2, 0], [0, 0, 3],])
sage: v = m.column(1)
sage: v
(1, 2, 0)
sage: m * v
(3, 4, 0)
sage: v * m
(1, 5, 0)
sage: u = v.row()
sage: u
[1 2 0]
sage: w = u.transpose()
sage: w
[1]
[2]
[0]
sage: u * w
[5]
sage: w * u
[1 2 0]
[2 4 0]
[0 0 0]
Mon, 12 Jan 2015 12:30:59 -0600https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?answer=25504#post-id-25504Comment by Silvia for <ol>
<li><p>Maybe you don't need to transpose your column vector. If <code>A</code> is a matrix and <code>v</code> is a vector, then <code>A * v</code> will use <code>v</code> as a column vector, and <code>v * A</code> will use <code>v</code> as a row vector.</p></li>
<li><p>If you want to make <code>v</code> a row vector, you can do <code>v.row()</code>.</p></li>
<li><p>the <code>column</code> method is for extracting a column of a matrix. You need to specify the index of the column (from 0 to nrows - 1).</p></li>
</ol>
<p>Illustration:</p>
<pre><code> sage: m = Matrix([[1, 1, 0],[0, 2, 0], [0, 0, 3],])
sage: v = m.column(1)
sage: v
(1, 2, 0)
sage: m * v
(3, 4, 0)
sage: v * m
(1, 5, 0)
sage: u = v.row()
sage: u
[1 2 0]
sage: w = u.transpose()
sage: w
[1]
[2]
[0]
sage: u * w
[5]
sage: w * u
[1 2 0]
[2 4 0]
[0 0 0]
</code></pre>
https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?comment=25505#post-id-255051. I need to transpose the vector because when i use it in a sum it says *unsupported operand parent(s) for '+': 'Full MatrixSpace of 3 by 1 dense matrices over Symbolic Ring' and 'Vector space of dimension 3 over Symbolic Ring'* , so i thought maybe it was because it had to be a row vector.
2. Why if i do `v.row()` it still says *row() takes at least 1 positional argument (0 given)* ?Mon, 12 Jan 2015 16:17:55 -0600https://ask.sagemath.org/question/25503/transpose-of-a-column-vector/?comment=25505#post-id-25505