본문 바로가기

formatter2

Python 지정된 정밀도로 과학적 표기법 없이 NumPy 배열을 예쁘게 출력합니다., Pretty-print a NumPy array without scientific notation and with given precision 질문 나는 이와 유사한 방식으로 NumPy 배열을 서식화하여 인쇄하는 방법을 알고 싶습니다: x = 1.23456 print('%.3f' % x) 만약 나는 부동 소수점의 numpy.ndarray를 인쇄하고 싶다면, 여러 소수점이 인쇄되는데, 종종 '과학적' 형식으로 인쇄되어 낮은 차원의 배열에도 읽기 어렵습니다. 그러나 numpy.ndarray는 문자열로 인쇄되어야 한다고 하는 것 같습니다, 즉, %s와 함께입니다. 이에 대한 해결책이 있을까요? 답변 numpy.set_printoptions를 사용하여 출력의 정밀도를 설정합니다: import numpy as np x = np.random.random(10) print(x) # [ 0.07837821 0.48002108 0.41274116 0.82993.. 2023. 11. 14.
Python 파일에 로그를 기록하고 표준 출력에 출력하기 위한 로거 설정, logger configuration to log to file and print to stdout 질문 I'm using Python's logging module to log some debug strings to a file which works pretty well. Now in addition, I'd like to use this module to also print the strings out to stdout. How do I do this? In order to log my strings to a file I use following code: import logging import logging.handlers logger = logging.getLogger("") logger.setLevel(logging.DEBUG) handler = logging.handlers.RotatingF.. 2023. 9. 9.