numpy中有一个函数可以让数组打印得更漂亮。
set_printoptions(suppress = True)换句话说,而不是这样:
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]])你会得到这个:
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.]])如何使此设置成为永久设置,以便每当我使用IPython时它都会这样做?
发布于 2009-12-07 13:31:04
我将此代码添加到~/.ipython/ipy_user_conf.py中的main()函数中
from numpy import set_printoptions
set_printoptions(suppress = True)而且它似乎起作用了。
在更高的IPython版本中,运行ipython profile create,然后打开~\.ipython\profile_default\ipython_config.py并编辑以下行以添加命令:
c.InteractiveShellApp.exec_lines = [
...
'import numpy as np',
'np.set_printoptions(suppress=True)',
...
]发布于 2009-11-25 23:15:40
您可以将它们添加到您的ipythonrc文件(位于Unix上的~/.ipython中)。你需要这些代码:
import_mod numpy
execute numpy.set_printoptions(suppress = True)您还可以将其添加到自定义配置文件或使用其他配置方法:
http://ipython.scipy.org/doc/stable/html/config/customization.html
https://stackoverflow.com/questions/1794161
复制相似问题