import numpy as np
a1 = np.array([1,2,3,4])
lista = [1,2,3,4]
a2 = np.array(lista)
print(lista)
print(a2)
print(type(a2)) # class 'numpy.ndarray'
listb = [x for x in range(10)]
print(listb) # [0,1,2,3,4,5,6,7,8,9]
b = np.arange(10)
print(b) # [0 1 2 3 4 5 6 7 8 9]
b1 = np.arange(1.5, 2, 0.1) #python range๋ ์ค์ํํ๋ X
print(b1) # [1.5 1.6 1.7 1.8 1.9]
python list๋ ์ฌ๋ฌ ํ์ ์ ๋ฐ์ดํฐ๊ฐ ๋ค์ด๊ฐ ์ ์์ง๋ง, ndarray๋ ํ๋์ ๋ฐ์ดํฐํ์ ๋ง ์ฒ๋ฆฌํ ์ ์๋ค.
listc = [1, 1.0, 'abc']
print(listc)
c = np.array(listc)
print(c)
"๋ถํ ํํฐ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ / ๋ถ์ฐ์์ ์ธ ์ธ๋ฑ์ค๋ฅผ ์ง์ ์ฃผ๋ ๊ฒ" ์ python list์์๋ ๋ถ๊ฐ๋ฅํ๋ค.
listd = list(''abcdefghijk)
print(listd) # ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
d = np.array(listd)
print(d) # ['a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k']
print(d[2]) # c
print(d[2:6:2]) # ['c' 'e']
print(a4[1,7,5]) # ['b' 'h' 'f']
filter1 = d > 'c'
print(a4[filter1]) # ['d' 'e' 'f' 'g' 'h' 'i' 'j' 'k']
.
.
.
ยป np.linspace
ยป np.zeros
ยป np.ones
ยป dtype / ndim / shape / size
ยป ์ฌ์น์ฐ์ฐ
np.linspace(1.5, 2.5, 10)
# [1.5 1.61111111 1.72222222 1.83333333 1.94444444 2.05555556
2.16666667 2.27777778 2.38888889 2.5 ]
np.zeros(5) # [0. 0. 0. 0. 0.]
np.zeros(5).astype(np.int64) # [0 0 0 0 0]
np.ones(10, dtype=np.int64) # [1 1 1 1 1 1 1 1 1 1]
a10 = np.arange(5,15)
print(a10) # [ 5 6 7 8 9 10 11 12 13 14]
print(a10.dtype) # int32
print(a10.ndim) # ์ฐจ์ : 1์ฐจ์
print(a10.shape) # (10, )
print(a10.size) # elements์ ๊ฐฏ์ : 10
lista = [1,2,3,4]
listb = [10,20,30,40]
print(lista + listb) # [1, 2, 3, 4, 10, 20, 30, 40]
a = np.array(lista)
b = np.array(listb)
print(a1+a2) # [11 22 33 44]
print(a1-a2) # [-9 -18 -27 -36]
print(a1*a2) # [10 40 90 160]
print(a1/a2) # [0.1 0.1 0.1 0.1]
print(a1%a2) # [1 2 3 4]
print( np.concatenate((a1,a2)) ) # [1 2 3 4 10 20 30 40]
np.sum(a1) # 10
np.min(a1) # 1
np.max(a1) # 4
np.std(a1) # 1.118033988749895