📖 코드로 방정식 표현하기
coefficient_matrix = [[2, 2, 1], [2, -1, 2], [1, -1, 2]]
constant_vector = [9,6,5]
📖 numpy
📖 numpy install
activate ml
conda install numpy
📖 python import numpy as np
📖 array creation
test_array = np.array([1, 4, 5, 8], float)
print(test_array)
type(test_array[3])
test_array = np.array([1, 4, 5, 8], float)
test_array
array([ 1., 4., 5., 8.])
test([test_array[3]])
numpy.float64
(출처 : https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/)
(출처 : https://www.slideshare.net/enthought/numpy-talk-at-siam)
# String Type의 데이터를 입력해도
test_array = np.array([1, 4, 5, "8"], float)
print(test_array)
array([ 1., 4., 5., 8.])
# Float Type으로 자동 형변환을 실시
print(type(test_array[3]))
numpy.float64
# Array(배열) 전체의 데이터 Type을 반환함
print(test_array.dtype)
dtype('float64')
# Array(배열) 의 shape을 반환함
print(test_array.shape)
(4,)
📖 array shape
Rank | Name | Example |
---|---|---|
0 | scalar | 7 |
1 | vector | [10, 10] |
2 | matrix | [[10, 10], [15, 15]] |
3 | 3-tensor | [[[ 1, 5, 9], [ 2, 6, 10]], [[ 3, 7, 11], [ 4, 8, 12]]] |
n | n-tensor |
test_array = np.array([1, 4, 5, "8"], float) # shape = (4,)
test_array
array([ 1., 4., 5., 8.])
matrix = [[1,2,5,8],[1,2,5,8],[1,2,5,8]]
np.array(matrix, int).shape
(3, 4)
tensor = [[[1,2,5,8],[1,2,5,8],[1,2,5,8]],
[[1,2,5,8],[1,2,5,8],[1,2,5,8]],
[[1,2,5,8],[1,2,5,8],[1,2,5,8]]]
np.array(tensor, int).shape
(4, 3, 4)
📖 array dtype
# data type을 integer로 선언
np.array([1, 2, 3], [4.5, 5, 6], dtype=int)
array([[1, 2, 3], [4, 5, 6]])
# data type을 float로 선언
np.array([1, 2, 3], [4.5, "5", "6"], dtype=np.float32)
array([[ 1. , 2. , 3. ], [ 4.5, 5. , 6. ]], dtype=float32)
(출처 : https://www.slideshare.net/enthought/numpy-talk-at-siam)
📖 array nbytes
# 32bits = 4bytes -> 6 * 4bytes
np.array([[1, 2, 3], [4.5, "5", "6"]], dtype=np.float32).nbytes
24
# 8bits = 1bytes -> 6 * 1bytes
np.array([[1, 2, 3], [4.5, "5", "6"]], dtype=np.int8).nbytes
6
# 64bits = 8bytes -> 6 * 8bytes
np.array([[1, 2, 3], [4.5, "5", "6"]], dtype=np.float64).nbytes
48
<이 게시물은 최성철 교수님의 numpy 강의 자료를 참고하여 작성되었습니다.>
본 포스트의 학습 내용은 [부스트캠프 AI Tech 5기] Pre-Course 강의 내용을 바탕으로 작성되었습니다.
부스트캠프 AI Tech 5기 Pre-Course는 일정 기간 동안에만 운영되는 강의이며,
AI 관련 강의를 학습하고자 하시는 분들은 부스트코스 AI 강좌에서 기간 제한 없이 학습하실 수 있습니다.
(https://www.boostcourse.org/)