Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 논문작성법
- Julia
- teps
- MATLAB
- 수치해석
- 논문작성
- IEEE
- Linear algebra
- Dear abby
- 옵시디언
- Numerical Analysis
- Python
- 에러기록
- pytorch
- JAX
- Zotero
- Statics
- matplotlib
- 생산성
- WOX
- 텝스
- 고체역학
- obsidian
- 우분투
- LaTeX
- 인공지능
- 딥러닝
- 수식삽입
- ChatGPT
- 텝스공부
Archives
- Today
- Total
뛰는 놈 위에 나는 공대생
Numpy에 대하여 본문
Numpy : python의 라이브러리 중 하나로 고성능 수치 계산에 유용하다. N차원 배열 객체를 제공한다.
Numpy에 대한 explanation : numpy.org/doc/stable/search.html
나처럼 아마추어 코딩하는 사람에게 manual과 google은 아주 고마운 존재다.
특히 manual의 장점은, 함수의 input의 data type 및 종류를 알려주고, output이 어떤 형태로 나올지 알려준다는 장점이 있다. 보통 일반 사람들이 쓴 글에 이런 세세한 부분까지 커버해주기는 힘들기 때문.
1. 배열 생성
1
2
3
4
5
6
7
8
9
10
11
12
|
import numpy as np
A = np.array([1,2,3,4]) #배열 array([1,2,3,4]) 생성
B = np.array([[1,2],
[3,4]])
C = np.zeros(5, dtype=int)
D = np.ones((2,3), dtype=complex)
E = np.arange(0, 19, 2) #일정한 간격으로 array를 만들고 싶을 때
F = np.linspace(0, 20, 6) #특정 범위 안에서 정해진 원소 갯수의 array를 만들고 싶을 때
G = np.random.random((2,2)) # [0,1) 사이의 랜덤값을 뽑아 정해진 사이즈의 배열 생성
H = np.random.normal(0,1,(2,2)) # 평균이 0이고 표준편차가 1인 배열
I = np.random.randint(0,10,(2,2))
# [0,10) 사이의 discrete uniform distribution에 따라 랜덤값 배열 생성 |
cs |
(+추가정보)
- numpy.arange([start, ]stop, [step, ]dtype=None)
start를 지정하지 않으면 default로 0을 부여, step을 지정하지 않으면 default로 1을 부여 - numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)
Return evenly spaced numbers over a specified interval. - 배열에 대한 정보
1
2
3
4
5
6
|
x = np.random.randint(10, size=(3,4))
x.dim # 2
x.shape # (3, 4)
x.size # 12
x.dtype # int64
|
cs |
2. 배열 인덱싱, 슬라이싱
3. 브로드캐스팅 : shape가 다른 array끼리 연산하는 것
A = [[1,2,3] [4,5,6] [7,8,9]]
B = [1]
C = [0 1 2]
D = [[0][1][2]]
이렇게 차원이 다른 행렬이 있어도
A+B
A+C
C+D
계산이 가능하다.
# 집계함수 : sum, min, max, mean 등 데이터에 대한 요약 통계
1
2
3
4
5
|
matrix = np.arange(9).reshape(3,3)
np.sum(matrix) # 결과는 32
np.min(matrix) # 0
np.max(matrix) # 8
np.mean(matrix) # 3.55555...
|
cs |
# 마스킹 연산 : True, False array를 통해서 특정 값들을 뽑아내는 방법
@ 조금씩 보충할 예정
코드를 작성하고 가져온 사이트 : colorscripter.com/
'프로그래밍 Programming' 카테고리의 다른 글
Git bash 명령어 정리 (4) 깃허브 (0) | 2021.07.20 |
---|---|
Git bash 명령어 정리 (3) 브랜치 (0) | 2021.07.20 |
Git bash 명령어 정리 (2) 기본 (0) | 2021.07.20 |
Git bash 명령어 정리 (1) 리눅스 (0) | 2021.07.19 |
[SQL] Database (0) | 2021.03.29 |
Comments