Skip to content

Instantly share code, notes, and snippets.

@syoh
Created April 27, 2015 05:24
Show Gist options
  • Save syoh/6cc54f3b44497b312ebb to your computer and use it in GitHub Desktop.
Save syoh/6cc54f3b44497b312ebb to your computer and use it in GitHub Desktop.
Control screen output precision
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