ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 17 Oct 2013 13:08:32 +0200Augmenting a vectorhttps://ask.sagemath.org/question/10618/augmenting-a-vector/There are simple ways to extend a matrix to form a larger matrix: I can `augment` it to add columns or `stack` it to add rows.
Is there something similar for simple vectors? Some method of a vector object which would return the same vector with one more element added to the end? Or do I have to write that myself?Thu, 17 Oct 2013 12:42:32 +0200https://ask.sagemath.org/question/10618/augmenting-a-vector/Answer by tmonteil for <p>There are simple ways to extend a matrix to form a larger matrix: I can <code>augment</code> it to add columns or <code>stack</code> it to add rows.</p>
<p>Is there something similar for simple vectors? Some method of a vector object which would return the same vector with one more element added to the end? Or do I have to write that myself?</p>
https://ask.sagemath.org/question/10618/augmenting-a-vector/?answer=15551#post-id-15551According to the tab completion, appart from the `.cartesian_product()` method that will make a couple of vectors, there seem no direct way to do this.
You can have a look at [this question](http://ask.sagemath.org/question/2902/append-a-variable-to-a-vector) and [that question](http://ask.sagemath.org/question/242/whats-the-vector-equivalent-to-pythons-list), though i would advise to keep track of the base ring of your initial vector (if needed) as follows:
sage: v = vector(QQ,[0,1,2]) ; v
(0, 1, 2)
sage: v.parent()
Vector space of dimension 3 over Rational Field
sage: v = vector(v.base_ring(), v.list() + [QQbar(1/2)]) ; v
(0, 1, 2, 1/2)
sage: v.parent()
Vector space of dimension 4 over Rational Field
Thu, 17 Oct 2013 13:08:32 +0200https://ask.sagemath.org/question/10618/augmenting-a-vector/?answer=15551#post-id-15551