How to make set_printoptions (suppress = True) permanent?

Numpy has a function that makes printing arrays easier.

set_printoptions(suppress = True)

In other words, instead:

array([[  0.00000000e+00,  -3.55271368e-16,   0.00000000e+00,
          1.74443793e-16,   9.68149172e-17],
       [  5.08273978e-17,  -4.42527959e-16,   1.57859836e-17,
          1.35982590e-16,   5.59918137e-17],
       [  3.00000000e+00,   6.00000000e+00,   9.00000000e+00,
          2.73835608e-16,   7.37061982e-17],
       [  2.00000000e+00,   4.00000000e+00,   6.00000000e+00,
          4.50218574e-16,   2.87467529e-16],
       [  1.00000000e+00,   2.00000000e+00,   3.00000000e+00,
          2.75582605e-16,   1.88929494e-16]])

You get the following:

array([[ 0., -0.,  0.,  0.,  0.],
       [ 0., -0.,  0.,  0.,  0.],
       [ 3.,  6.,  9.,  0.,  0.],
       [ 2.,  4.,  6.,  0.,  0.],
       [ 1.,  2.,  3.,  0.,  0.]])

How to make this parameter permanent so that it does it when I use IPython?

+3
source share
3 answers

I added this to the function main()in ~/.ipython/ipy_user_conf.py:

from numpy import set_printoptions
set_printoptions(suppress = True)

and it seems to work.

In later versions of IPython, run ipython profile create, then open ~\.ipython\profile_default\ipython_config.pyand edit the following line to add the command:

c.InteractiveShellApp.exec_lines = [
        ...
        'np.set_printoptions(suppress=True)',
        ...
        ]
+2
source

You can add them to your ipythonrcfile (located ~/.ipythonon Unix). You will need the lines:

import_mod numpy
execute numpy.set_printoptions(suppress = True)

:

http://ipython.scipy.org/doc/stable/html/config/customization.html

+1

, - $PYTHONPATH, printopts say, :

import numpy
numpy.set_printoptions(suppress = True)

, . numpy from printopts import numpy. import.

.

: - $PYTHONSTARTUP printopts.py. . , python numpy, .

, , np.py,

from numpy import *
set_printoptions(supress=True)

import np, , .

If you are not opposed to hacking, just add the set_printoptions () call to the file the numpy/__init__.py, but you must have write access to the numpy installation and remember to repeat the hack when upgrading python or numpy. I do not think it's a good idea.

0
source

Source: https://habr.com/ru/post/1723833/


All Articles