Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble coercing a vector directly to a matrix #10613

Closed
jonhanke opened this issue Jan 12, 2011 · 3 comments
Closed

Trouble coercing a vector directly to a matrix #10613

jonhanke opened this issue Jan 12, 2011 · 3 comments

Comments

@jonhanke
Copy link

Vector to matrix coercion appears not to work unless going through a list.

sage: v = vector(QQ,[1,2,3])
sage: v
(1, 2, 3)
sage: type(v)
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
sage: 
sage: Matrix(QQ, 3,1,v)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/jonhanke/Documents/SAGE/sage-4.6/<ipython console> in <module>()

/Users/jonhanke/Documents/SAGE/sage-4.6/local/lib/python2.6/site-packages/sage/matrix/constructor.pyc in matrix(*args, **kwds)
    660             ring = rings.ZZ
    661             
--> 662     return matrix_space.MatrixSpace(ring, nrows, ncols, sparse=sparse)(entries)
    663         
    664 

/Users/jonhanke/Documents/SAGE/sage-4.6/local/lib/python2.6/site-packages/sage/matrix/matrix_space.pyc in __call__(self, entries, coerce, copy, rows)
    403             return self(entries.matrix(), copy=False)
    404 
--> 405         return self.matrix(entries, copy=copy, coerce=coerce, rows=rows)
    406 
    407     def change_ring(self, R):

/Users/jonhanke/Documents/SAGE/sage-4.6/local/lib/python2.6/site-packages/sage/matrix/matrix_space.pyc in matrix(self, x, coerce, copy, rows)
   1134                 x = new_x
   1135             
-> 1136         return self.__matrix_class(self, entries=x, copy=copy, coerce=coerce) 
   1137      
   1138     def matrix_space(self, nrows=None, ncols=None, sparse=False):

/Users/jonhanke/Documents/SAGE/sage-4.6/local/lib/python2.6/site-packages/sage/matrix/matrix_rational_dense.so in sage.matrix.matrix_rational_dense.Matrix_rational_dense.__init__ (sage/matrix/matrix_rational_dense.c:5774)()

TypeError: entries must be coercible to a list or integer
sage: Matrix(QQ, 3,1, list(v))
[1]
[2]
[3]
sage: 

CC: @williamstein @jonhanke

Component: linear algebra

Keywords: matrix, vector

Issue created by migration from https://trac.sagemath.org/ticket/10613

@rbeezer
Copy link
Mannequin

rbeezer mannequin commented Jan 13, 2011

comment:1

If you leave out the dimensions (which would be inferred from the vector), it is possible to build a matrix from a vector.

sage: w=vector(QQ, [1,2,3])
sage: A = Matrix(QQ, w); A
[1 2 3]
sage: A.parent()
Full MatrixSpace of 1 by 3 dense matrices over Rational Field

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@jdemeyer
Copy link

jdemeyer commented Mar 1, 2018

Changed author from Jonathan Hanke to none

@jdemeyer
Copy link

jdemeyer commented Mar 1, 2018

comment:6

Fixed in #24742

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants