class Foo: def __init__(self): pass def getx(self): return self.x foo = Foo() foo.x = 1 print(foo.getx()) C++ 로 위와 같이 코드를 작성했으면 foo.x = 1 라인에서 아래와 같은 오류가 출력됐을것이다. error: ‘class Foo’ has no member named ‘x’ 근데 Python 에서는 에러가 안난다. 저렇게 하면 없던 멤버변수 x 가 생긴다. 실제 사용 예 YOLOv8 에서 nn.Sequential 클래스의 객체에 i, f, type 이라는 멤버변수를 위 방법을 이용해 정의한다. https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn..
python의 Built-in Functions 중 eval 이라는 함수가 있다. eval 은 문자열을 입력으로 받는다. eval 의 출력은 입력받은 문자열이 Python interpreter로 해독가능하다면 그 문자열을 "코드"로 보고 실행한다. 그렇지 않은 경우는 예외가 발생한다. eval('1+2') # 3 eval("'1'+'2'") # "12" 이런것도 가능하다. class Foo: def __init__(self, x): self.x = x pass foo = eval("Foo(x=5)") print(foo.x) # 5 too = eval("Foo")(15) print(too.x) # 15 활용 방법은 무궁무진하다. 실제 사용 예 YOLOv8 의 경우 모델 아키텍쳐가 컨피그 파일에 정의돼있다...
클래스의 함수 바깥에서 변수를 정의하면 이 변수는 static 멤버변수가 된다. 이 변수를 static 멤버변수로서 값을 수정하고 싶다면 클래스이름.변수 로 접근하여 수정해야한다. 그렇지않고 self.변수 나 객체.변수 이런식으로 값을 수정하게 되면 static의 특성을 잃고 멤버 변수로써 재정의가 된다. 아래의 예제코드에서 foo.x 가 static 멤버변수이다. class foo(object): x = 'original' def __init__(self): self.y = 'hi' def setx(self, x): foo.x = x c1 = foo() print(c1.x) # original print(c1.y) # hi c2 = foo() print(c2.x) # original print(c2.y..
conda update conda conda update anaconda https://docs.anaconda.com/anaconda/install/update-version/ Updating from older versions — Anaconda documentation Updating from older versions Follow the instructions below to update Anaconda to the latest version. Windows: Open Anaconda Prompt. macOS or Linux: Open a terminal window. To update to the latest version of Anaconda, enter these commands: #upda..
https://stackoverflow.com/questions/3229419/how-to-pretty-print-nested-dictionaries How to pretty print nested dictionaries? How can I pretty print a dictionary with depth of ~4 in Python? I tried pretty printing with pprint(), but it did not work: import pprint pp = pprint.PrettyPrinter(indent=4) pp.pprint(mydict) I ... stackoverflow.com
with open(filename) as f: mylist = f.read().splitlines() https://stackoverflow.com/questions/15233340/getting-rid-of-n-when-using-readlines Getting rid of \n when using .readlines() I have a .txt file with values in it. The values are listed like so: Value1 Value2 Value3 Value4 My goal is to put the values in a list. When I do so, the list looks like this: ['Value1\n', 'Value... stackoverflow.com
https://stackoverflow.com/a/45669280 How to block calls to print? Is there a way to stop a function from calling print? I am using the pygame.joystick module for a game I am working on. I created a pygame.joystick.Joystick object and in the actual loop of the game stackoverflow.com import os, sys class HiddenPrints: def __enter__(self): self._original_stdout = sys.stdout sys.stdout = open(os.dev..
def compute_iou(bboxes1, bboxes2, bbox_format='cxcywh', normalized=True): if bbox_format == 'cxcywh': # if bboxes are composed of center point xy and wh/2. cx1, cy1, w1, h1 = np.split(bboxes1, 4, axis=1) cx2, cy2, w2, h2 = np.split(bboxes2, 4, axis=1) x11 = cx1 - w1 / 2 y11 = cy1 - h1 / 2 x12 = cx1 + w1 / 2 y12 = cy1 + h1 / 2 x21 = cx2 - w2 /2 y21 = cy2 - h2 /2 x22 = cx2 + w2 /2 y22 = cy2 + h2 /..
- Total
- Today
- Yesterday
- 백준 11437
- 백준 1766
- 순열
- 가장 긴 증가하는 부분 수열
- 백트래킹
- FairMOT
- 인공지능을 위한 선형대수
- ㅂ
- 이분탐색
- 문제집
- Lowest Common Ancestor
- C++ Deploy
- 조합
- 파이참
- PyCharm
- MOT
- 단축키
- 백준
- LCA
- 자료구조
- 위상 정렬 알고리즘
- 백준 11053
- cosine
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |