목록전체 글 (260)
일상 코딩
https://arxiv.org/ arXiv.org e-Print archive Donate to arXiv Please join the Simons Foundation and our generous member organizations in supporting arXiv during our giving campaign September 23-27. 100% of your contribution will fund improvements and new initiatives to benefit arXiv's global scientifi arxiv.org
https://paperswithcode.com/ Papers with Code - The latest in Machine Learning Papers With Code highlights trending Machine Learning research and the code to implement it. paperswithcode.com
리눅스 버전 : 18.04 파이썬 버전 : 3.8 가상환경 pg : virtualenv python 설치 확인 설치폴더 만들기 $ mkdir aiml 폴더로 이동 $ cd aiml virutalenv 설치 (파이썬 버전에 따라 설치하는 명령이 다르다.) $ python3.8 -m pip install virtualenv 가상환경 만들기 $ vitualenv --python=python3.8 MLvenv # or $ python3.8 -m venv MLvenv 가상환경 활성화 $ source ~/MLvenv/bin/activate 가상환경 비활성화 $ deactivate [Tip] 가상환경 실행 명령 별칭으로 정의하기 $ cd #엔터; 홈으로 디렉토리 변경 $ ls -al .bashrc $ nano .ba..
// ---- Function as a param func add( _ a: Int, _ b: Int) -> Int { return a+b } func subtract( _ a: Int, _ b: Int)-> Int{ return a - b } func multiple( _ a: Int, _ b: Int) -> Int{ return a * b } var function = add function(4,2) function = subtract function(4,2) func printResult(_ function: (Int, Int) -> Int, _ a: Int,_ b: Int){ let result = function(a,b) print(result) } printResult(add, 10, 5) /..
// In-out parameter var value = 3 func incrementAndPrint( _ value: inout Int) { value += 1 print(value) } incrementAndPrint(&value) //결과값: 4 함수 안에서 value를 1 증가시키고 print 할때는 입력값의 타입을 나타내는 Int 앞에 inout을 작성해 준다.
파이썬과 비교해 Swift 만의 함수 작성법 1. 파이썬 함수 작성법 def tenTimes(x): return x * 10 if __init__ == "main": tenTimes(10) ## 결과값: 100 입력(x)을 받으면 return으로 x * 10을 그대로 리턴. 2. Swift(스위프트) 함수 작성법 func tenTimes( _ num: Int) -> Int { return num * 10 } tenTimes(10) // 결과값: 100 함수 작성시 리턴값 형태를 표시해줘야하고(-> Int), 함수 작성시 언더바( _ )를 사용해야, 사용시 요소 num를 따로 뜨지도 않고, 함수 작동시 필요하지도 않게 된다.
class CompressedGene: def __init__(self, gene: str) -> None: self._compress(gene) # "_"은 클래스 외부에서 사용되지 않게 하기 위한 비공개 처리 문구이다. def _compress(self, gene: str) -> None: self.bit_string: int = 1 # 1로 시작/ 유전코드를 2진수로 변환 후 저장할 변수. for nucleotide in gene.upper(): self.bit_string > i & 0b11 # 마지막 2비트를 추출한다. if bits == 0b00: # A gene += "A" elif bits == 0b01: # C gene += "C" elif bits == 0b10: # G gene += ..
암호화 전체 코드는 아래와 같다. from secrets import token_bytes from typing import Tuple def random_key( length: int ) -> int: # length 만큼 임의의 바이트를 생성한다. tb: bytes = token_bytes(length) # token_byte() 메서드 사용하여 pseudo-random 데이터 생성한다. # 바이트를 비트 문자열로 변환한 후 반환한다. return int.from_bytes(tb,"big") # 암호화 과정 메소드 def encrypt( original: str ) -> Tuple[int, int]: original_bytes: bytes = original.encode() # 문자열을 encode(..

위의 식은 파이 계산을 위한 무한급수 라이프 니츠 공식(Leibniz Formula)이다. 이를 무한히 더하면 파이값을 가질 수 있게 된다. 이를 코드로 나타내면 import numpy as np import time def calculate_pi(n_terms:int) -> float: upNum: float = 4.0 downNum: float = 1.0 multiNum: float = 1.0 pi: float = 0.0 start = time.time() for _ in range(n_terms): pi += multiNum * ( upNum / downNum ) downNum += 2.0 multiNum *= -1.0 end = time.time() return pi, end-start if __..
part.00 메모이제이션을 이용한 피보나치 알고리즘 n = int(input()) memo = {0: 0, 1: 1} def fibo(n): if n in memo: return memo[n] else: ret = fibo(n-1) + fibo(n-2) memo[n] = ret return ret print(fibo(n)) 일반적인 리스트를 이용하는 것이 아닌, dictionary()를 이용하여 key값으로 value를 빠르게 찾도록 만들었다. part.01 아래 코드는 해보나치 수열 단일값을 출력하는 코드이다. from functools import lru_cache @lru_cache( maxsize = None ) def fib4( n: int ) -> int: if n < 2: # 기저조건 re..