일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- 핑거스타일
- Docker
- C++
- JSON
- Selenium
- 기타 연주
- 오류
- windows forms
- Python
- paramiko
- C
- Visual Studio
- SSH
- mysql
- OpenCV
- Numpy
- error
- ubuntu
- nvidia-smi
- C#
- YOLO
- Linux
- pandas
- pytorch
- VS Code
- label
- 컨테이너
- 채보
- 프로그래머스
- pip
- Today
- Total
목록Python (117)
기계는 거짓말하지 않는다
Numpy의 any를 이용한 필터 import numpy as np num_in_array = np.array([0]) x = np.array([ [2 ,33 ,1 ,6 ,24 ,0], [2 ,56 ,2 ,3 ,8 ,5], [1 ,2 ,12 ,65 ,4 ,1], [9 ,22 ,77 ,4 ,3 ,10], [15 ,0 ,2 ,73 ,2 ,3], [2 ,42 ,19 ,11 ,55 ,0] ]) # Filter by num_in_array if num_in_array is not None: print(x[:, 5:6] == num_in_array) print((x[:, 5:6] == num_in_array).any(1)) # 마지막 열이 num_in_array안의 숫자와 하나라도 일치할 경우 # any의 매개변수..
Scikit Learn 라이브러리에서 제공하는 데이터 셋 중 Iris 꽃의 데이터이다. from sklearn.datasets import load_iris iris_dataset = load_iris() print(type(iris_dataset) # sklearn.utils.Bunch print(iris_dataset.keys()) # dict_keys(['data', 'target', 'frame', 'target_names', 'DESCR', 'feature_names', 'filename']) print(iris_dataset['DESCR'][:193]) ''' .. _iris_dataset: Iris plants dataset -------------------- **Data Set Chara..
from PIL import Image import cv2 img = cv2.imread("img.png") # 299 x 507 h, w, c = img.shape # height, width, channel print(h, w, c) img = Image.open("img.png") w, h = img.size # wdith, height print(w, h)
import torchmodel = # 모델 생성# 모델 저장save_name = "model_final"torch.save(model.state_dict(), f"Directory/{save_name}.pth")# 모델 불러오기load_name = "model_final"model.load_state_dict(torch.load(f"Directory/{load_name}.pth")) # 경로, 저장 모델 이름# 설정 값 세부 저장checkpoint = { 'model': model.state_dict(), 'optimizer': optimizer.state_dict(), 'lr_scheduler': lr_scheduler.state_dict(), 'epoch': epoch}torch.save(c..
Python에서 파일 open시 볼 수 있는 에러이다. 실제로 파일 권한이 없어서 열 수 없는 경우 파일 권한을 변경하면 된다. 권한이 있는데도 발생한다면 Windows에서 거의 대부분 file이 아닌 directory를 open하고 있을 수 있다. path를 확인하고 directory를 열고 있지 않은지 검사한다.
리스트 내포를 이용하거나 [value] * n으로 표현하면 된다. # 길이 100 list를 생성하고 0으로 초기화 temp_list = [0 for i in range(100)] temp_list = [0] * 100 # [value] * n
Numpy 배열을 transpose를 이용하여 축을 바꿀 수 있다. transpose 함수의 매개변수는 축의 번호이고 축의 개수만큼 입력해야 한다. (3차원 -> 3개) 축의 인덱스는 0부터 시작한다. 예를 들어 행, 열의 2차원 배열이 있다면 transpose(1, 0) (열, 행)으로 행, 열을 바꿀 수 있다. 이때, 첫 번째 매개변수는 행, 두 번째는 열이 되며 행 매개변수에 열(1)로 바꾸고 열 매개변수에 행(0)으로 바꾼다. shape가 (3, 2, 4) (높이, 행, 열)인 3차원 배열이 있을 때, transpose(1, 2, 0)을 하게 되면 index 0 = 높이, 1 = 행, 2 = 열이 되고 (3(높이), 2, 4)의 높이 자리에 행(index=1, shape=2) (3, 2(행), 4..
클래스에 여러 인스턴스 변수의 기준에 따라 정렬할 때 비교함수 구현 # lt(a, b): a = b operator.ge(a, b) operator.__ge__(a, b) # boolean 값으로 해석할 수도 있고, # 그렇지 않은 임의의 값을 반환할 수도 있음 class TempClass: def __init__(self, string:str, index:int): if type(string) is not str: raise Exception("not string") if type(index) is no..