목록Records of/Learning (53)
SiLaure's Data
- Array Operation (like vector) --> Universal Function numpy array를 쓰는 가장 큰 이유는 vector처럼 사용할 수 있기 때문이다. e.g. arr1 = np.array([1, 2, 3, 4, 5]) --> (1, 2, 3, 4, 5) == vector 그렇기 때문에 scipy, matplotlib, scikit-learn, pandas, tensorflow, pytorch 등 대부분의 데이터분석 라이브러리들이 numpy array를 사용한다. 대부분의 데이터 분석 라이브러리들은 벡터를 사용하는데, 그 벡터가 바로 numpy array로 표현되기 때문. 데이터 분석은 99.9% 데이터를 벡터로 표현하여 분석하기 때문에, 이 특징은 굉장히 중요하다. 벡..
- Numpy Array 만들기 1. np라는 이름으로 numpy library를 불러온다. import numpy as np 2. Python list 선언한다. data = [1, 2, 3, 4, 5] # data, type(data) 3. Python 2차원 리스트(행렬) 선언한다. data2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 4. Python list를 numpy array로 변환한다. arr1 = np.array(data) # 2번처럼 미리 Python list를 선언하는 대신 list를 안에서 선언하고 바로 np.array를 만들 수 있다. np.array([1, 2, 3, 4, 5]) ndarray : numpy.ndarray(n-dimensional array..
- What is Numpy? "numerical python"의 약자. 컴퓨터공학의 한 분야로, 실수 계산이 python의 취약점을 보완하기 위한 도구로 사용한다. 데이터가 vector(정형데이터 --표 형식)로 표시되기 때문에 벡터 연산이 필요하다. numerical python을 이해하기 위해서는 Numerical Computing과 을 알아야 한다. 1. Numerical Computing : 컴퓨터가 실수값을 효과적으로 계산할 수 있도록 하는 연구 분야 2. Vector Arithmetic : 벡터 연산 --데이터가 벡처로 표현되기 때문에 필요하다. (Vecotr는 숫자의 모음을 말한다.) numpy는 다양한 머신러닝 라이브러리들에 의존성을 가지고 있고, 일반 파이썬 리스트에 비해 성능이 월등히..
- File I/O : 프로그램에서 파일을 열고 닫는 것 open()을 이용해서 열고 close()를 이용해서 닫는다. close를 하지 않으면 jupyter가 계속해서 파일을 점유하고 있게 되어, 시스템 낭비가 일어난다. with open() 을 쓰면 동시에 처리할 수 있기 때문에 편하다. open() 함수는 다양한 옵션을 제공하지만 기본적으로는 txt파일을 여는 것을 기본으로 가정한다. 다른 타입의 파일을 열기 위해선 다른 라이브러리들이 필요하다. e.g. csv, excel 파일을 열기 위해 pandas, csv, openpyxl 라이브러리를 사용할 수 있다. e.g. png, jpg 파일을 열기 위해 PIL, opencv 라이브러리를 사용할 수 있다. e.g. pk, pkl 파일을 열기 위해 pi..
Python 프로그래밍의 마지막. - I/O란? : input/output의 약자 프로그램 입장에서 들어오는 모든 데이터를 input, 나가는 모든 데이터를 output이라고 한다. 메인 메모리 입장에서 생각하는 들어오고 나가는 모든 데이터에 대해서 I/O 처리라고 부른다. (단, CPU와의 소통은 제외) 통상적으로는 Unix 환경(터미널 환경)에서 부르던 용어임 사용자로 부터 키보드로 입력받는 것 : stdin 사용자에게 다시 모니터로 출력되는 것 : stdout 프로그램은 메인 메모리 상에 존재하기 때문에 스토리지로부터 파일을 불러오는 것도 input이고, 프로그램의 결과를 스토리지에 저장하는 것도 output이다. 이러한 작업을 file I/O로 통칭한다. 스토리지와 프로그램 사이의 I/O를 fil..
- 함수 정의의 다양한 형태 연습하기 1. 가장 흔하게 사용되는 경우 : 함수 parameter와 return이 모두 존재하는 경우 def add(a, b) : return a + b def get_loss(model, matric) : ... ... ... return model.predict(result, metric=[metric]) 2. 함수 parameter는 없고 return이 존재하는 경우 : parameter가 없어도 뻔한 일을 할 때 e.g. csv 파일을 불러오는 함수 : 불러오는 data가 존재하기 때문에 지정된 파일만 가져오면 된다. 따라서 return만 있다. def get_data() : data = pd.read_csv("test.csv") return data 3. 함수 pa..
- 함수는... Iteration Statement를 사용하는 고오급 기법 프로그래밍에 있어 필수적 도구 함수의 기능을 정확히 알고 사용하면 프로그래밍을 고급지고 편하게 할 수 있다. - Function이란? 수학적인 의미의 함수와 개념은 비슷하지만 역할이 다르다. input이 들어와서 정해진 규칙에 따라 처리되어 output이 나온다는 개념은 같지만, 프로그래밍에서 하나의 함수는 하나의 기능을 나타낸다. 하나의 기능 : 입력받은 2개의 숫자를 더한다, 들어온 텍스트를 정제한다, 받은 이미지를 greyscale로 변경한다 등등 정확하게는 특정 기능을 구현한 코드 묶음이다.한마디로 하나의 기능을 구현하기 위한 코드들를 함수라고 한다. - 함수를 쓰는 이유? 재 사 용 성 때문이다. 똑같은 구조의 코드는 보..
1. if 지옥 다음 코드의 실행결과를 예측해보자. a = "Life is too short, you need python" if "wife" in a: print("wife") elif "python" in a and "you" not in a: print("python") elif "shirt" not in a: print("shirt") elif "need" in a: print("need") else: print("none") 내가 푼 풀이 if "wife" in a: print("wife") # 'wife'가 있으면 'wife'를 출력해라 elif "python" in a and "you" not in a: print("python") # 'python'이 있고 'you'가 없으면 'python..