NumPy 배열이 일정 크기 이상이 되면 print를 사용하여 출력시 다음처럼 생략이 됩니다.
[[ 0] [ 1] [ 2] ... [9997] [9998] [9999]] |
사용한 코드입니다.
import numpy as np a = np.arange(10000) b = np.expand_dims(a, axis=1) print(b) |
2021. 10. 4 - 최초작성
배열 출력시 옵션을 변경을 위해 다음 코드를 추가하면 전체 배열을 모두 출력할 수 있습니다.
import sys
np.set_printoptions(threshold=sys.maxsize)
import numpy as np import sys np.set_printoptions(threshold=sys.maxsize) a = np.arange(10000) b = np.expand_dims(a, axis=1) print(b) |
np.set_printoptions(threshold=np.nan)를 사용할 경우 Python3에서는 다음과 같은 에러가 발생할 수 있습니다.
Traceback (most recent call last):
File "d:/code/python/test.py", line 7, in <module>
np.set_printoptions(threshold=np.nan)
File "C:\Users\webnautes\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\arrayprint.py", line 245, in set_printoptions
floatmode, legacy)
File "C:\Users\webnautes\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\arrayprint.py", line 86, in _make_options_dict
raise ValueError("threshold must be non-NAN, try "
ValueError: threshold must be non-NAN, try sys.maxsize for untruncated representation
출처