반응형

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





출처

https://stackoverflow.com/questions/55258882/threshold-must-be-numeric-and-non-nan-when-printing-numpy-array-why-numpy-nan 

 

반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts