통계 함수 만들기 중심 경향성 : 평균, 중앙값, 분위수(4분위, 100분위=퍼센트), 최빈값,산포도 : 분산(variance), 표준편차(standard deviation), 범위(range)상관 관계 : 공분산(Covariance), 상관계수(Correlation) def mean(x):"""리스트 x의 모든 아이템들의 평균을 계산해서 리턴x = [x1, x2, ..., xn]mean = (x1 + x2 + ... + xn) / n :param x: 원소 n개인 (1차원) 리스트:return: 평균""" return sum(x) / len(x) def median(x):"""리스트 x를 정렬했을 때 중앙에 있는 값을 찾아서 리턴n이 홀수이면, 중앙값을 찾아서 리턴n이 짝수이면, 중앙에 있는 두 개 값..
python
import numpy as np # numpy.ndarray 타입의 객체를 생성 A = np.array([ [1, 2, 3], [4, 5, 6] ]) B = np.array([ [1, 2], [3, 4], [5, 6] ]) print(A) print(B) print(A.shape) # 2x3 행렬 print(B.shape) # 3x2 행렬 (2, 3)(3, 2) nrows, ncols = B.shape print(nrows, 'x', ncols) 3 x 2 # slicing: 특정 행, 특정 열의 원소들을 추출하는 방법 # list[row][column], ndarray[row, column] print(A[0, 0]) print(B[1, 1]) 14 print(A[0:2, 0:3]) print(A[0..
# plotting을 위한 패키지 임포트import matplotlib.pyplot as plt # 막대 그래프(bar chart)# 영화 제목movies = ['Annie Hall', 'Ben-Hur', 'Casablanca', 'Gandhi', 'West Side Story']# 아카데미 시상식에서 받은 상의 갯수num_oscars = [5, 11, 3, 8, 10] plt.bar(movies, num_oscars)font_name = {'fontname':'Gulim'}dictionary 변수로 'fontname = 'Gulim'' 을 매번 입력하는 동작을 생략할 수 있다. plt.title('아카데미 수상작', font_name)plt.ylabel('수상 갯수', font_name)plt.show..
https://matplotlib.org/ # plotting을 위한 패키지 임포트import matplotlib.pyplot as plt 자료 입력year = [1950, 1960, 1970, 1980, 1990, 2000, 2010]gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3] 그래프 출력# plot: 선 그래프 생성plt.plot(years, gdp, color = 'green', marker = 'o')plt.title('연도별 GDP', fontname='Gulim')plt.xlabel('Year')plt.ylabel('GDP(Billions of $)') # show: 그래프를 화면에 보여주는 기능plt.show() 출력 결과 ..