np.set_printoptions()了解一下
需求1.需要以科学计数法输出:np.set_printoptions(suppress = True), 不需要以科学计数法输出:np.set_printoptions(suppress = False)
需求2.需要控制小数点后位数为N,np.set_printoptions(precision= N)
需求3.数组太长打印出来会太长,控制输出的元素的个数,np.set_printoptions(threshold = 1)
import numpy as np
a1 = np.array([0.0012345, 0.01234567891234, 111.1234567891111, 1])
np.set_printoptions(suppress=True)
print(a1)
np.set_printoptions(suppress=False)
print(a1)
np.set_printoptions(precision=3, suppress=True)
print(a1)
a1 = np.zeros(100)
np.set_printoptions(threshold = 1)
print(a1)
结果如下:
[ 0.001 0.012 111.123 1. ]
[1.234e-03 1.235e-02 1.111e+02 1.000e+00]
[ 0.001 0.012 111.123 1. ]
[0. 0. 0. ... 0. 0. 0.]