Hi,

if you want to make explicit that you apply the operation to each entry,
you can still do:

sage: A = Matrix(ZZ,2,[3,3,3,3]) 
sage: A.apply_map(lambda x:x//3)
[1 1]
[1 1]
sage: _.parent()
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring


This method works for many things, that might not make sense as an
operation on matrices:

sage: A.apply_map(arctan)
[arctan(3) arctan(3)]
[arctan(3) arctan(3)]

It also allows not to be confused when applying an operator that is well
defined on the matrix, but does not have the same meaning than applying it
on each entry:

sage: A.apply_map(exp)
[e^3 e^3]
[e^3 e^3]

sage: exp(A)
[1/2*e^6 + 1/2 1/2*e^6 - 1/2]
[1/2*e^6 - 1/2 1/2*e^6 + 1/2]

Ciao,
Thierry


On Wed, Nov 01, 2017 at 02:36:59PM -0700, Simon Brandhorst wrote:
> sage: A = Matrix(ZZ,2,[3,3,3,3])
> sage: A
> [3 3]
> [3 3]
> sage: A//3
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> ...
> 
> TypeError: unsupported operand parent(s) for //: 'Full MatrixSpace of 2 by 
> 2 dense matrices over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense 
> matrices over Integer Ring'
> sage: A/3
> [1 1]
> [1 1]
> sage: (A/3).base_ring()
> Rational Field
> 
> 
> What I would like is a matrix over the Integers. Not an integral matrix 
> over the rationals.
> This seems so elementary that I wonder if I am missing something?
> 
> (A/3).change_ring(ZZ) 
> 
> is too ugly. Ticket?
> 
> And similar for p-adic integers, polynomial rings in one variable etc.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to