Ask Your Question

Revision history [back]

You can bypass the Sage preparser by appending r (for raw) to numerical input.

sage: import numpy as np
sage: np.mgrid[-1:1:5jr]
array([-1. , -0.5,  0. ,  0.5,  1. ])

Note that some preparsing is still going on with -1 and 1 which are converted to Sage integers by the preparser before going to numpy's mgrid. If you want to feed numpy's mgrid with raw Python integers:

sage: np.mgrid[-1r:1r:5jr]
array([-1. , -0.5,  0. ,  0.5,  1. ])

It's the same result, except less conversion was done on the way.

On a related note, you can get a Python integer by doing

sage: int(1)

but when you do this, the preparsing stage means what is really done is

int(Integer(1))

so the Python integer 1 is converted to a Sage integer and back to a Python integer.

Bypassing the Sage preparser with

sage: 1r

gets you the Python integer straight away.