# How do I "tidy up" error terms in a matrix?

Hi - I have some calculation results in the form of a complex Gram matrix which are all supposed to be integers (or "obvious" algebraic numbers which I know about). However inevitably in the course of creating them as inner products, some "error" terms arise which are of a size of the order of 10^-16 (real and/or complex). Is there an easy way to "clean up" my matrix with some sort of threshold, so that things which differ from a user-specified list of algebraic numbers by less than a tiny amount like 10^-15, are assumed to be the relevant algebraic number? At the moment I'm having to do it by a bunch of hideous if-statement contortions but I'm sure there's a better way! Many thanks in advance for any help.

I've wondered similar things myself. It would be nice to have something like `fnormal` in Maple. Can you apply `round` in some way using a `map` command to help. For example, `round(1+10.^(-16),5)` gives `1.0`.

thanks - as an example for future reference, I used John's suggestion below in the following form: mat.apply_map( lambda x: (d*abs(x)^2).round()/d ); where I knew that the largest denominator for the abs values was d (one has to be a little more careful with complex entries)