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.Sun, 27 Jan 2019 16:34:47 +0100Convert real matrix into Integer matrixhttps://ask.sagemath.org/question/45203/convert-real-matrix-into-integer-matrix/Suppose I have a real matrix with integer entries
A = matrix(RR,[[1,2,3],[4,5,6]])
I would like to convert it to an Integer matrix (ZZ). I can do it element by element but is there a function that will do this for the entire matrix. Doing B=ZZ(A) will return an error message
unable to coerce <type 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'> to an integer.
raykanSun, 27 Jan 2019 16:34:47 +0100https://ask.sagemath.org/question/45203/Cannot convert int to sage.rings.integer.Integerhttps://ask.sagemath.org/question/8099/cannot-convert-int-to-sageringsintegerinteger/I created a minimal example in the file bad.py
from sage.all import *
j = 0
m = matrix(3,3)
m.insert_row(j, [1,1,1])
Then from sage:
sage: load bad.py
TypeError: Cannot convert int to sage.rings.integer.Integer
I think I can see an easy workaround, I can wrap all the 1's in Integer() (or change the name of the file to .sage so the preparser does it), but why is that necessary? Is this a bug? Why would sage not be able to convert int to Integer? Isn't that a pretty obvious conversion?
paragonMon, 02 May 2011 14:23:12 +0200https://ask.sagemath.org/question/8099/