pip install jupyter
jupyter notebook
pip install numpy
import numpy as np
a = np.array([1,2,3])
print(a)
print([1,2,3])
print(type(a))
a = np.array([1,2,3])
b = [1, 2, 3]
print(a,b)
a = np.append(a,4)
b.append(4)
print(a,b)
import numpy as np
a = np.array([1,2,3])
b = [1, 2, 3]
print(a,b)
a = a + np.array([5])
b = b + [5, 6]
print(a,b)
import numpy as np
a = np.array([1,2,3])
b = [1, 2, 3]
print(a,b)
a = a * np.array([2])
b = b * 2
print(a,b)
a = np.array([1,2,3])
print(a)
print(type(a))
print(a.dtype)
print(a.ndim)
print(a.shape)
np.zeros((n, m))
np.ones((n, m))
np.full((n, m), value)
np.empty((n, m))
등으로 배열 생성이 가능
a = np.zeros((3,4))
print(a)
3*4 배열 0으로 저장
a = np.ones((3,4))
print(a)
3*4 배열 1으로 저장
a = np.full((3,4), 5)
print(a)
3*4 배열 5으로 저장
a = np.empty((3,4))
print(a)
3*4 배열 쓰레기 값으로 저장
a = np.random.rand(2,2)
print(a)
2*2 배열 랜덤 값으로 저장
a = np.random.rand(2,3,4)
print(a)
3차원 배열도 가능
a = np.zeros((3,4))
print(a)
print(type(a))
print(a.dtype)
print(a.ndim)
print(a.shape)
a = np.array(
[
[1,2,3],
[4,5,6],
[7,8,9],
])
print(a)
print(a[1][0]) #4출력
print(a.ndim)
print(a.shape)
a = np.array(
[
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11,12,13,14,15],
[16,17,18,19,20],
]
)
print(a[1:4, 2:4])
a = np.array(
[
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11,12,13,14,15],
[16,17,18,19,20],
]
)
for i in range(0,4):
for j in range(0,4):
print(a[i:i+2, j:j+2])
x = np.array(
[
[1, 2],
[3, 4],
]
)
y = np.array(
[
[5, 6],
[7, 8],
]
)
print(x+y)
print(np.add(x,y))
print(x-y)
print(np.subtract(x,y))
print(x*y)
print(np.multiply(x,y))
print(x/y)
print(np.divide(x,y))
print(x@y)
print(np.matmul(x,y))
x = np.array(
[
[1, 2],
[3, 4],
]
)
print(x)
print(x.T)
print(np.transpose(x))
x = np.array(
[
[1, 2],
[3, 4],
]
)
print(x.reshape(1,4))
print(x.reshape(4,1))
a = np.array([1,2,3,4,5,6,7,8,9,10,11,12])
print(a.ndim)
print(a.shape)
a = a.reshape(2,6)
print(a)
print(a.ndim)
print(a.shape)