λͺ©μ°¨
μ΄λ²μλ numpyμ λ°°μ΄μ λν΄ μμ보λλ‘ νμ!
1_ λ°°μ΄μ λ°μ΄ν° νμ (dtype)
νμ΄μ¬ 리μ€νΈμ λ¬λ¦¬ numpyλ κ°μ λ°μ΄ν° νμ λ§ μ μ₯μ΄ κ°λ₯νλ€!
μ’ λ₯ : int, float, str, bool
arr = np.array([0,1,2,3,4])
print(arr)
print(arr.dtype)
print(arr.astype(float))
γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘
[0 1 2 3 4]
int32
[0. 1. 2. 3. 4.]
dtypeμ λ°μ΄ν° νμ μ λ°ν νλλ°
int μ¦ μ μν λ°μ΄ν°μμ μ μ μλ€.
astype()μ λ°μ΄ν° νμ μ λ³κ²½νλ ν¨μμ΄λ€.
μ λ ₯ν λ°μ΄ν°νμ μΌλ‘ λ³κ²½μ νλ€.
arr = np.array([1,2,3,4], dtype=float)
print(arr)
γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘
[0. 1. 2. 3. 4.]
ndarrayλ₯Ό μμ±ν λ μμ²λΌ λ°μ΄ν° νμ μ μ§μ ν μ μλ€.
2_ λ°°μ΄μ μμ± (ndim, shape)
list = [0,1,2,3]
arr = np.array(list)
print(arr.ndim)
print(arr.shape)
print(len(arr))
γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘
1
(4,)
4
ndimμ λ°°μ΄μ μ°¨μμ λ°ννλ€.
μμ μμλ 1μ°¨μμ΄λΌλ λ»μ΄λ€.
shapeμ (ν,μ΄)μ λ°ννλ€.
μλ 4ν 0μ΄ μ΄λΌλ λ»μ΄λ€.
lenμ μκ³ μλ―μ΄ κΈΈμ΄λ₯Ό λ°ννλ€.
list = [[0,1,2],[3,4,5]]
arr = np.array(list)
print(arr.ndim)
print(arr.shape)
print(len(arr))
γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘
2
(2,3)
2
μμ μμλ '2μ°¨μ, 2ν 3μ΄'μ΄λΌλ λ»μ΄λ€.
λν, κΈΈμ΄κ° '2'κ° λ°νμ΄ λμλλ° 2νμ§λ¦¬ λ°°μ΄μ΄κΈ° λλ¬Έμ κΈΈμ΄κ° 2μ΄λ€.
ν¬κΈ° μ‘°μ
arr = np.array([1,2,3,4,5,6])
arr.shape = 3,2
print(arr)
γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘γ
‘
[[1 2]
[3 4]
[5 6]]
shapeμ κ°μ ν λΉνμ¬ μ§μ ν¬κΈ°λ₯Ό μ‘°μ ν μ μλ€.
'π | Python > νμ΄μ¬ λΌμ΄λΈλ¬λ¦¬' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
numpy_(1)_μκ° (0) | 2021.11.17 |
---|
λκΈ