๐Ÿš€ Languege/Python

python -numpy(7) ๋ฐฐ์—ด์˜ ์ž๋ฃŒํ˜•

mini_world 2020. 3. 30. 18:49
๋ชฉ์ฐจ ์ ‘๊ธฐ

๋ฐฐ์—ด 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