๋ชฉ์ฐจ
์ ๊ธฐ
๋ฐฐ์ด ndarrayํด๋์ค๋ ๋ฐ์ดํฐ๊ฐ ๊ฐ์ ์๋ฃํ์ด์ด์ผ ํฉ๋๋ค!
array๋ช
๋ น์ผ๋ก ๋ฐฐ์ด ์์ฑ ์ ๋ช
์์ ์ผ๋ก ์ง์ ํ๋ ค๋ฉด dtype์ธ์ ์ฌ์ฉํฉ๋๋ค.
import numpy as np
# ----------------------------------------------------------
# ๋ฐฐ์ด์ ํ์
ํ์ธ
x = np.array([1, 2, 3])
print(x.dtype)
x = np.array([1.2, 2.2, 3.1])
print(x.dtype)
x = np.array(['A', 'B', 'C'])
print(x.dtype) # Unicode
x = np.array([True, False])
print(x.dtype)
# ----------------------------------------------------------
x = np.array([1, 2, 3, '๊ฐ'], dtype='U')
print(x.dtype)
print(type(x[1]))
x = np.array([1, 2, 3, '๊ฐ'], dtype='O') # object class๋ ์ํผ!
print(x.dtype)
x = np.array([1, 2, 3], dtype='i')
print(x.dtype)
x = np.array([1.1, 1.4, 2.6, 6.7], dtype='f')
print(x.dtype)
# ----------------------------------------------------------
# ์ฐ์ฐ์ ์ซ์ ์๋ฃํ์ผ๋๋ง ๊ฐ๋ฅํ๋ค ???????????????์๋๋๋ฐ????????????????????????????
n = np.array([1, 2, 3], dtype='I')
print(n[1]+n[0])
o = np.array([1, 2, 3, '๊ฐ'], dtype='O') # ????????????????????
print(n[1]+n[0])
[์ฝ๋ ์คํ ๊ฒฐ๊ณผ]
int32
float64
bool
<class 'numpy.str_'>
object
int32
float32
3
3
728x90