Created
April 27, 2015 05:24
-
-
Save syoh/6cc54f3b44497b312ebb to your computer and use it in GitHub Desktop.
Control screen output precision
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import contextlib | |
@contextlib.contextmanager | |
def printoptions(*args, **kwargs): | |
original = np.get_printoptions() | |
np.set_printoptions(*args, **kwargs) | |
yield | |
np.set_printoptions(**original) | |
v = np.random.random(10) | |
with printoptions(precision=3, suppress=True): | |
print(v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment