반응형
간혹 numpy array를 출력하다보면 소수점이 길거나, 지수표현으로 되어있어 수치를 정확히 파악하기가 어려운 경우가 있다.
이 때, numpy의 printoption 설정을 변경하면 손쉽게 설정할 수 있다.
자세한 옵션들은 아래 링크 참조
numpy.org/doc/stable/reference/generated/numpy.set_printoptions.html
numpy.set_printoptions — NumPy v1.20 Manual
If True, always print floating point numbers using fixed point notation, in which case numbers equal to zero in the current precision will print as zero. If False, then scientific notation is used when absolute value of the smallest number is < 1e-4 or the
numpy.org
import numpy as np
# numpy float 출력 옵션 변경(소수점 3자리까지 출력, array의 원소 값 자체가 변경되지는 않음)
np.set_printoptions(precision=3, suppress=True)
print(np.array([0.12345])
>>> [0.123]
반응형