일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- Visual Studio
- windows forms
- paramiko
- nvidia-smi
- Numpy
- Python
- ubuntu
- label
- 오류
- Linux
- SSH
- pandas
- C++
- 컨테이너
- C#
- JSON
- C
- VS Code
- mysql
- pytorch
- error
- OpenCV
- Selenium
- Docker
- 핑거스타일
- YOLO
- 기타 연주
- 채보
- pip
- 프로그래머스
- Today
- Total
목록Python (107)
기계는 거짓말하지 않는다
import os dir_path = "test/files" file_names = os.listdir(dir_path) for name in file_names: src = os.path.join(dir_path, name) dst = name.replace("old_char", "new_char") dst = os.path.join(dir_path, dst) os.rename(src, dst)
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의 매개변수..
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)
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..
TypeError: 'int' object is not subscriptable 인덱스로 지정할 수 없는 경우(단일 값) # TypeError: 'int' object is not subscriptable intValue = 10 print(intValue[3]) intArray = [1, 2, 3] print(intArray[0][1]) TypeError: list indices must be integers or slices, not str TypeError: string indices must be integers 숫자 형식 인덱스에 Key 형식으로 받은 경우 # TypeError: list indices must be integers or slices, not str intArray = [1, 2..