일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- SQL
- pandas
- 프로그래머스
- R
- 코딩테스트
- 오라클
- 데이터 분석
- 실습
- 실기
- 빅분기
- sklearn
- Kaggle
- seaborn
- matplotlib
- 튜닝
- oracle
- level 2
- level 1
- Oracel
- 알고리즘
- Numpy
- Python
- 카카오
- 빅데이터 분석 기사
- 파이썬
- python3
- 머신러닝
- Today
- Total
목록Numpy (14)
라일락 꽃이 피는 날
1. np.linalg.inv 역행렬을 구할 때 사용한다. 이때, 모든 차원의 값이 같아야 한다. x = np.random.rand(3, 3) np.linalg.inv(x) 행렬의 곱 (@) x @ np.linalg.inv(x) np.matmul(x, np.linalg.inv(x)) 2. np.linalg.solve Ax = B 형태의 선형대수식 솔루션을 제공한다. A = np.array([[1, 1], [2, 4]]) B = np.array([25, 64]) x = np.linalg.solve(A, B) # [18. 7.] np.allclose(A@x, B) # True
Boolean indexing ndarry 인덱싱 시, bool 리스트를 전달하여 True인 경우만 필터링하여 반환한다. x = np.random.randint(1, 100, size=10) # [75 12 80 63 69 82 24 35 92 22] x[x % 2 == 0] # array([12, 80, 82, 24, 92, 22]) x[x 50)] # array([75, 12, 80, 63, 69, 82, 24, 92, 22])
1. ravel 다차원 배열을 1차원으로 변경한다. order='C' (row 우선 변경) / 'F' (column 우선 변경) x = np.arange(15).reshape(3, 5) np.ravel(x) # array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) np.ravel(x, order='C') # array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) np.ravel(x, order='F') # array([ 0, 5, 10, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14]) 2. flatten 다차원 배열을 1차원으로 변경한다. ravel과 다르게 원본 데이터가 아닌 ..
1. sin (사인) import numpy as np import matplotlib.pylab as plt x = np.linspace(-5, 5, 100) sin = np.sin(x) plt.plot(x, sin) plt.title('sin(x)') plt.show() 2. cos (코사인) x = np.linspace(-5, 5, 100) cos = np.cos(x) plt.plot(x, cos) plt.title('cos(x)') plt.show() 3. tan (탄젠트) x = np.linspace(-3, 3, 100) tan = np.tan(x) plt.plot(x, tan) plt.ylim([-10, 10]) plt.title('tan(x)') plt.show()
1. zeros 0으로 채워진 지정된 모양과 유형의 새로운 배열을 반환한다. numpy.zeros(shape, dtype) shape : 반환할 배열의 모양 dtype : 반환할 데이터 유형 np.zeros(5) # array([ 0., 0., 0., 0., 0.]) np.zeros((5,), dtype=int) # array([0, 0, 0, 0, 0]) np.zeros((2, 1)) # array([[ 0.], # [ 0.]]) 2. ones 1로 채워진 지정된 모양과 유형의 새로운 배열을 반환한다. numpy.ones(shape, dtype) shape : 반환할 배열의 모양 dtype : 반환할 데이터 유형 np.ones(5) # array([1., 1., 1., 1., 1.]) np.ones((..
1. 연산 함수 add(덧셈), subtract(뺄셈), multiply(곱셈), divide(나눗셈) x = np.array([1, 2, 3]) y = np.array([4, 5, 6]) np.add(x, y) # array([5, 7, 9]) np.subtract(x, y) # array([-3, -3, -3]) np.multiply(x, y) # array([ 4, 10, 18]) np.divide(x, y) # array([0.25, 0.4 , 0.5 ]) 2. 통계 함수 min(최솟값), max(최댓값), argmin(최솟값의 인덱스), argmax(최댓값의 인덱스), mean(평균), median(중앙값), var(분산), std(표준편차) x = np.array([1, 2, 3, 4, 5, ..
1. 배열 합치기 (concatenate) 기준이 되는 축을 따라 배열 순서를 결합한다. a = np.array([[1, 2], [3, 4]]) b = np.array([[5, 6]]) np.concatenate((a, b), axis=0) # array([[1, 2], # [3, 4], # [5, 6]]) np.concatenate((a, b.T), axis=1) # array([[1, 2, 5], # [3, 4, 6]]) np.concatenate((a, b), axis=None) # array([1, 2, 3, 4, 5, 6]) 2. 배열 나누기 (split) 배열을 여러 개의 하위 배열로 분할한다. numpy.split(ary, N) 축을 따라 N등분하여 분할한다. x = np.arange(9.0..
1. np.random.rand 0~1 사이의 임의의 균일 분포 값을 반환한다. np.random.rand() # 0.5644040985351038 np.random.rand(3) # array([0.15907147, 0.56814351, 0.65641927]) np.random.rand(3,2) # array([[0.1728781 , 0.41835388], # [0.39280028, 0.09229667], # [0.0272809 , 0.02512556]]) 2. np.random.randn n : normal distribution (정규 분포) -1~1 사이의 임의의 정규 분포 값을 반환한다. np.random.randn() # -0.6184246409845511 np.random.randn(3) #..