1) Tech

[Numpy] 생략(' ... ') 제거

Tech_holic 2020. 1. 28. 10:26
반응형

1. introduction
python을 사용하다보면 numpy라는 파이썬 라이브러리를 사용하게 된다.

numpy는 기본적으로 array를 기본단위로 사용하는데, 쉽게 생각하면 차원에 따라 matrix, vector가 된다. 

(1차원 = vector, 2차원 = matrix,...)

2. problem
하지만, numpy 배열(array)의 내용물을 하나하나 확인하고 싶은데 array가 너무 크면 일부 array 안의 data가 ...로 생략 되어버린다.

나 또한 이부분 때문에 고생을 했고 이 옵션을 해결하기 위해서 다양한 방법을 찾아보았다.



3. solution

import numpy as np #numpy library
np.set_printoptions(threshold=np.inf, linewidth=np.inf) #inf = infinity 


* np.set_printoptions에 관하여
linewidth : int, optional
The number of characters per line for the purpose of inserting line breaks (default 75).
=> 1줄당 문자 수 (기본값 75)

threshold : int, optional
Total number of array elements which trigger summarization rather than full repr (default 1000).
=> 1개의 배열당 총 element 갯수 (기본값 1000)

출처:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html

반응형