Difference between r1.3 and the current
@@ -1,3 +1,9 @@
https://numpy.org/
----
<<tableofcontents>>
= ? =
''from https://wikidocs.net/22849''{
np.array
@@ -11,7 +17,16 @@
np.random.randint(숫자1, 숫자2, size = 난수갯수)}
= ndarray =
[[맷플럿립,Matplotlib]]
tmp
{
numpy의 histogram 으로 도수분포도 그리기 (+matplotlib사용)
https://wikidocs.net/23258
}
= NumPy Types? =
== ndarray ==
a가 있을 때a.shape : 크기 (x, y)를 돌려줌.
a.reshape(x, y) : 크기 x, y로 바꿈.
@@ -26,14 +41,91 @@
np.sum(a) : 합
np.arange(n) : 수열을 만듦. array형으로.
= tmp; from Simplenote =
// 2018-10-04 작성인데 뭐 하다가 적은건지 기억이 안나네
{{{
import numpy as np
배열 만들기
x = np.array([1, 2.0, 3.0])
다차원 배열 만들기 (2차원 배열: 행렬)
>>> a=np.array([[1,2],[3,4]])
>>> print(a)
[[1 2]
[3 4]]
>>> a.shape
(2, 2)
>>> a.dtype #원소의 자료형
dtype('int32')
>>> b=np.array([[3,0],[0,6]])
>>> a+b
array([[ 4, 2],
[ 3, 10]])
>>> a*b
array([[ 3, 0],
[ 0, 24]])
원소 접근
>>> x=np.array([[51,55],[14,19],[0,4]])
>>> print(x)
[[51 55]
[14 19]
[ 0 4]]
>>> x[0]
array([51, 55])
>>> x[0][1]
55
>>> for row in x: print(row);
[51 55]
[14 19]
[0 4]
>>> z = x.flatten()
>>> print(z)
[51 55 14 19 0 4]
>>> z[np.array([0,2,4])] # 인덱스가 0,2,4인 원소 얻기
array([51, 14, 0])
>>> x>15
array([[ True, True],
[False, True],
[False, False]])
>>> z>15
array([ True, True, False, True, False, False])
>>> z[z>15] # 15 초과인 값만 구하기
array([51, 55, 19])
행렬의 내적
>>> A = np.array([[1, 2], [3, 4]])
>>> A.shape
(2, 2)
>>> B = np.array([[5, 6], [7, 8]])
>>> np.dot(A, B)
array([[19, 22],
[43, 50]])
}}}
= NumPy의 간단한 통계 기능들 =
from https://wikidocs.net/23279
{
||[[평균,mean,average]] ||np.average(x) ||
||[[중앙값,median]] - curr see [[대표값,평균값,중앙값,최빈값]] ||np.median(x) ||
||최빈값 ||np.bincount(x).argmax() ||
||[[분산,variance]] ||np.var(x) ||
||[[표준편차,standard_deviation]] ||np.std(x) ||
}
본격적인 통계 기능은 보통 [[팬더스,Pandas]]를 사용.
= 기타 =
MathInspector
https://mathinspector.com/
A Visual Programming Environment for Scientific Computing
Free open source software designed for students, content creators, and professional mathematicians
[[RR:넘파이,NumPy]]
----
Up: [[파이썬,Python]]
1. ? ¶
from https://wikidocs.net/22849
{
np.array
np.random.randint(9)는 0부터 9까지 숫자중 아무 숫자나 하나 생성
np.random.randint(숫자1, 숫자2, size = 난수갯수)
}
{
np.array
a = [1,2,3,4,5] # list a를 만들어서 b = np.array(a) # array 자료형으로 바꾸자 # 여기서 type(b) 하면 numpy.ndarray 라고 나온다. nd는 다차원(n-dimensional)을 뜻함.np.sqrt, multiply(내적), max, min, argmax, argmin(최대값 최소값의 index)
np.random.randint(9)는 0부터 9까지 숫자중 아무 숫자나 하나 생성
np.random.randint(숫자1, 숫자2, size = 난수갯수)
}
2.1. ndarray ¶
a가 있을 때
a.shape : 크기 (x, y)를 돌려줌.
a.reshape(x, y) : 크기 x, y로 바꿈.
a.shape : 크기 (x, y)를 돌려줌.
a.reshape(x, y) : 크기 x, y로 바꿈.
np.zeros(n) : 0.으로만 이뤄진 배열을 만듦
np.ones(n) : 1.로만
다차원 배열일때는
np.zeros((행 갯수, 열 갯수)) 처럼 괄호를 두번 써야 함
np.ones(n) : 1.로만
다차원 배열일때는
np.zeros((행 갯수, 열 갯수)) 처럼 괄호를 두번 써야 함
원소의 index를 찾으려면 (list처럼 .index()가 아님)
np.where('찾으려는 원소' == array이름)
np.where('찾으려는 원소' == array이름)
np.sum(a) : 합
np.arange(n) : 수열을 만듦. array형으로.
np.arange(n) : 수열을 만듦. array형으로.
3. tmp; from Simplenote ¶
// 2018-10-04 작성인데 뭐 하다가 적은건지 기억이 안나네
import numpy as np 배열 만들기 x = np.array([1, 2.0, 3.0]) 다차원 배열 만들기 (2차원 배열: 행렬) >>> a=np.array([[1,2],[3,4]]) >>> print(a) [[1 2] [3 4]] >>> a.shape (2, 2) >>> a.dtype #원소의 자료형 dtype('int32') >>> b=np.array([[3,0],[0,6]]) >>> a+b array([[ 4, 2], [ 3, 10]]) >>> a*b array([[ 3, 0], [ 0, 24]]) 원소 접근 >>> x=np.array([[51,55],[14,19],[0,4]]) >>> print(x) [[51 55] [14 19] [ 0 4]] >>> x[0] array([51, 55]) >>> x[0][1] 55 >>> for row in x: print(row); [51 55] [14 19] [0 4] >>> z = x.flatten() >>> print(z) [51 55 14 19 0 4] >>> z[np.array([0,2,4])] # 인덱스가 0,2,4인 원소 얻기 array([51, 14, 0]) >>> x>15 array([[ True, True], [False, True], [False, False]]) >>> z>15 array([ True, True, False, True, False, False]) >>> z[z>15] # 15 초과인 값만 구하기 array([51, 55, 19]) 행렬의 내적 >>> A = np.array([[1, 2], [3, 4]]) >>> A.shape (2, 2) >>> B = np.array([[5, 6], [7, 8]]) >>> np.dot(A, B) array([[19, 22], [43, 50]])
4. NumPy의 간단한 통계 기능들 ¶
from https://wikidocs.net/23279
{
}
본격적인 통계 기능은 보통 팬더스,Pandas를 사용.
{
평균,mean,average | np.average(x) |
중앙값,median - curr see 대표값,평균값,중앙값,최빈값 | np.median(x) |
최빈값 | np.bincount(x).argmax() |
분산,variance | np.var(x) |
표준편차,standard_deviation | np.std(x) |
본격적인 통계 기능은 보통 팬더스,Pandas를 사용.
5. 기타 ¶
MathInspector
https://mathinspector.com/
A Visual Programming Environment for Scientific Computing
Free open source software designed for students, content creators, and professional mathematicians
https://mathinspector.com/
A Visual Programming Environment for Scientific Computing
Free open source software designed for students, content creators, and professional mathematicians
Up: 파이썬,Python