# Revision history [back]

### Set the precision of imported methods

How to set the precision of "numpy" methods?

e.g., for calculating the singular values of a matrix using numpy methods

sage: R = RealField(100)
sage: R
Real Field with 100 bits of precision
sage: A = matrix(R ,2,2, [1.746, 0.940, 1.246, 1.898])
sage: A
[ 1.7460000000000000000000000000 0.94000000000000000000000000000]
[ 1.2460000000000000000000000000  1.8980000000000000000000000000]
sage: A.parent()
Full MatrixSpace of 2 by 2 dense matrices over Real Field
with 100 bits of precision
sage: A = np.array(A) # the precision (100 bits) does not preserve in "numpy"
sage: U,sig,V = numpy.linalg.svd(A)
sage: sig
array([  1.08490731e+06,   1.97535694e+00])
# the precision (100 bits) does not preserve in "numpy", hey only 8 digits here


### Set the precision of imported methods

How to set the precision of "numpy" methods?

e.g., for calculating the singular values of a matrix using numpy methods

sage: R = RealField(100)
sage: R
Real Field with 100 bits of precision
sage: A = matrix(R ,2,2, [1.746, 0.940, 1.246, 1.898])
sage: A
[ 1.7460000000000000000000000000 0.94000000000000000000000000000]
[ 1.2460000000000000000000000000  1.8980000000000000000000000000]
sage: A.parent()
Full MatrixSpace of 2 by 2 dense matrices over Real Field
with 100 bits of precision
sage: A = np.array(A) # the precision (100 bits) does not preserve in "numpy"
sage: U,sig,V = numpy.linalg.svd(A)
sage: sig
array([  1.08490731e+06,   1.97535694e+00])
# the precision (100 bits) does not preserve in "numpy", hey only 8 digits here


NumPy Data types

sage: np.array([1, 2, 3], dtype='f')

array([ 1., 2., 3.], dtype=float32)

That's a choice. However, I'd like some more convenient method like "numpy.set_digits(100)"...

### Set the precision of imported methods

How to set the precision of "numpy" methods?

e.g., for calculating the singular values of a matrix using numpy methods

sage: R = RealField(100)
sage: R
Real Field with 100 bits of precision
sage: A = matrix(R ,2,2, [1.746, 0.940, 1.246, 1.898])
sage: A
[ 1.7460000000000000000000000000 0.94000000000000000000000000000]
[ 1.2460000000000000000000000000  1.8980000000000000000000000000]
sage: A.parent()
Full MatrixSpace of 2 by 2 dense matrices over Real Field
with 100 bits of precision
sage: A = np.array(A) # the precision (100 bits) does not preserve in "numpy"
sage: U,sig,V = numpy.linalg.svd(A)
sage: sig
array([  1.08490731e+06,   1.97535694e+00])
# the precision (100 bits) does not preserve in "numpy", hey only 8 digits here