본문 바로가기
728x90
반응형

python5

[leet code] Linked List Random Node (python) Problem Example 1: Input ["Solution", "getRandom", "getRandom", "getRandom", "getRandom", "getRandom"] [[[1, 2, 3]], [], [], [], [], []] Output [null, 1, 3, 2, 2, 3] Explanation Solution solution = new Solution([1, 2, 3]); solution.getRandom(); // return 1 solution.getRandom(); // return 3 solution.getRandom(); // return 2 solution.getRandom(); // return 2 solution.getRandom(); // return 3 // ge.. 2020. 12. 17.
[Python] 여러개의 사진 일괄 사이즈 변경하기 glob() glob 함수를 이용해서 여러개의 사진 일괄 사이즈 변경하는 방법입니다. glob함수 뒤에 해당 파일의 경로를 작성하면 됩니다. 저는 train_ 으로 시작되는 모든 파일을 가져올 것이기 때문에 train_* 이라고 작성하였습니다. 만약 img로 시작되는 모든 파일을 가지고 오길 원하시면, img* 이렇게 하시면됩니다. files = glob.glob('./data/train/train_*') for f in files: title, ext = os.path.splitext(f) if ext in ['.png']: img = Image.open(f) img_resize = img.resize((224, 224)) img_resize.save(title+ext) 2020. 9. 13.
[Matplotlib] plot title 한글 깨짐 오류 해결 matplotlib.rcParams['font.family'] ='Malgun Gothic' matplotlib.rcParams['axes.unicode_minus'] =False 한글 title을 설정하면 다음과 같이 한글 깨짐 현상이 나타난다. 다음과 같은 오류는 시스템 폰트를 사용하고 있기 때문이고, 이를 해결하려면 폰트를 한글폰트로 지정해주면 된다. 코드는 다음과 같다. import matplotlib matplotlib.rcParams['font.family'] ='Malgun Gothic' matplotlib.rcParams['axes.unicode_minus'] =False 위 코드를 실행한 후 다시 plot 하면, 한글로 된 title이 깨지지 않고 잘 나오는 것을 확인할 수 있다. 2020. 7. 13.
[Python] 변수 타입 확인하기 type() Python은 변수에 대입한 값에 의해 type이 결정되며, 사이즈의 제한이 없습니다. 아래에서는 변수의 type을 확인하는 방법에 대해 알아보겠습니다. type(변수) - 변수의 타입을 확인하는 함수 입니다. a 에 10을 대입한 후 a의 타입을 확인해보면, 10은 정수 타입이기 때문에 print(type(a))를 했을 때 int 가 출력됩니다. 아래는 f에 실수 타입의 데이터를 대입한 후 type을 확인했을 때의 예제입니다. type을 출력했을 때 float 이 출력되는 것을 확인 할 수 있습니다. 2020. 7. 13.
728x90
반응형