'''import numpy as np
data = [1,2,3]
a=np.array(data)
print(a)
a_rb = list(a)
print(a_rb)
data = [[1,2,3],[4,5,6],[7,8,9]]
a=np.array(data)
print(a)
print(a[0:2])
print(a[0,2])
print(a[0][2])
print("--------------------")
print(a[0:3:2,0:3:2])
print("--------------------")
a_1 = a[0:3:2,0:3:2]
print(a_1)
print("--------------------")
print(a_1.shape)
print(a.shape)
print("--------------------")
print(np.sum(a, axis=0))
print(np.sum(a, axis=1))
print("--------------------")
import numpy as np
data = [[[1,2],[3,4]],[[5,6],[7,8]]] # 3차원 배열 (텐서)
a=np.array(data)
print(a)
print(np.sum(a))
print(a.shape)
print("--------------------")
import numpy as np
array = np.array([[[1, 0, 1],[0, 0, 1]],
[[1, 1, 1],[1, 0, 1]],[[1, 0, 1],[0, 1, 1]]])
print(array.shape)
print(array)
print("--------------------")
print(array.ndim)
print(array.sum(axis = 0))
print(array.sum(axis = 0).shape)
print(array.sum(axis = 1))
print(array.sum(axis = 1).shape)
print(array.sum(axis = 2))
print(array.sum(axis = 2).shape)
print("--------------------")
print(np.arange(5))
print(np.arange(5.0))
print(np.arange(2,8))
print(np.arange(2,10,2))
'''
import numpy as np
X=np.linspace(1.0, 100.0, num=100)
print(X)
#배열에 균일한 간격으로 1부터 100까지 10개의 숫자를 채워줌
print(X.shape)
print("-----------")
X_4_25=np.reshape(X,(4, 25))
print(X_4_25.shape)
print(X_4_25)
X_4_5_5=X_4_25.reshape(4,5,5, order='C')
print(X_4_5_5.shape)
X_new=X.reshape(-1,25, order='C')
print(X_new.shape)
print(X_new)
print("-----------")
array= np.arange(15, 0, -1).reshape(3, 5)
print(array)
print(array.shape)
print(array.ndim)
print(array.sum(axis=0))
print(array.sum(axis=1))
'''
print("-----------")
import numpy as np
# Indexing and Slicing 1D array
array1 = np.arange(10) # subset of 1D array
print(array1)
print(array1[5])
print(array1[0:5])
import numpy as np
# Indexing and Slicing 2D array
array2=np.arange(20).reshape(4, 5) # subset of 2D array
print(array2)
print(array2[1])
print(array2[1:3])
print(array2[0, 4])
print(array2[0:3, 1:3])
print(array2[1])
print(array2[1:3])
print(array2[0, 4])
print(array2[0:3, 1:3])
import numpy as np
# Indexing and Slicing 3D array
array3=np.arange(24).reshape(2, 3, 4) # subset of 3D array
print(array3)
print(array3[1])
print(array3[1, 0])
print(array3[1, 1, 0:3])
print(array3[1, :, 1:3])
print("------------------")
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
print(np.hstack([a, b]))
print(np.hstack([a, b]).shape)
print(np.vstack([a, b]))
print(np.vstack([a, b]).shape)
print(np.stack([a, b], axis=0))
print(np.stack([a, b], axis=0).shape)
print(np.stack([a, b], axis=1))
print(np.stack([a, b], axis=1).shape)
print(np.dstack([a, b]))
print(np.dstack([a, b]).shape)
print(np.linspace(4.0, 6.0, num=5))
print(np.linspace(4.0, 6.0, num=5, endpoint=False))
print(np.linspace(4.0, 6.0, num=5, retstep=True))
print("----------------")
a = np.ones((2,5))
print(a)
a = np.full((2,5), 3)
b = np.array(range(20)).reshape((2,10))
print(np.ndim(b))
print(np.shape(b))
print(np.dtype)
print("----------------")
data = [[1,2,3],[4,5,6],[7,8,9]]
array_3=np.array(data)
print(array_3)
array_C = np.reshape(array_3,(1, -1), order='C')
print(array_C)
array_F = np.reshape(array_3, (1, -1), order='F')
print(array_F)
import numpy as np
array = np.arange(10)
print(array)
array_new = np.reshape(array, (2, -1))
print(array_new)
array_C = np.reshape(array, (2, -1), order='C')
print(array_C)
print("--------------")
data=np.array([1,2,3])
print(data+data)
print(data**2)
print(data*20)
import numpy as np
a = np.array([1,2,3,4])
b = np.array([5,6,7,8])
c = a + b
print(c)
c_other=np.add(a,b)
print(c_other)
d = a - b
print(d)
f = a*b
print(f )
g = a/b
print(g)
import numpy as np
# 2차원 배열
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
# 전체 합 구하기
sum_val1 = np.sum(a)
print("전체 합:", sum_val1)
# 축별 합 구하기
sum_val2 = np.sum(a, axis=0)
print("열별 합:", sum_val2)
sum_val3 = np.sum(a, axis=1)
print("행별 합:", sum_val3)
# 전체 곱 구하기
prod_val = np.prod(a)
print("전체 곱:", prod_val)
# 1차원 배열
x = np.array([1, 2], float)
y = np.array([3, 4], float)
print("x:", x)
print("y:", y)
print("x와 y의 내적:", np.dot(x, y))
print("x와 y의 내적 (inner):", np.inner(x, y))
print("x와 y의 원소별 곱:", x * y)
# 2차원 배열의 행렬 내적과 내적
print("a와 b의 행렬 내적 (dot):", np.dot(a, b))
print("a와 b의 내적 (inner):", np.inner(a, b))
# 1차원 배열의 외적 및 교차 곱
print("x와 y의 외적 (outer):", np.outer(x, y))
# 2차원 벡터를 3차원 벡터로 확장하여 교차 곱 계산
x_3d = np.array([x[0], x[1], 0])
y_3d = np.array([y[0], y[1], 0])
print("x와 y의 교차 곱 (cross):", np.cross(x_3d, y_3d))
# 2차원 배열을 1차원으로 변환하여 외적 계산
print("a와 b의 외적 (outer):", np.outer(a.ravel(), b.ravel()))
#ㅇㅣ거 교슈님 코드 안 돌아가서 챗쥐피티 돌림 ㅋㅋ아
print("-----------------------")
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0., 2., 0.1)
plt.figure(figsize=(7,5))
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("Drawing graph")
plt.plot(x, x, 'r--', x, x**2, 'bs-.', x, x**3, 'g^--')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
def h(t):
return np.exp(-t)
def f(t):
return np.exp(-t) * np.cos(2*np.pi*t)
def g(t):
return np.sin(np.pi*t)
t1 = np.arange(0.0, 5.0, 0.01)
t2 = np.arange(0.0, 5.0, 0.01)
t3 = np.arange(0.0, 5.0, 0.01)
plt.plot(t1, f(t1), t2, g(t2),'r-', t3,h(t3),'g--')
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("Drawing graph")
plt.grid()
plt.show()
arr = np.array([('jin', 25, 67), ('suho', 18, 77)],
dtype=[('name', 'U10'), ('age', 'i4'), ('weight', 'f4')])
print(arr)
print(arr['name'])
print(arr['age'])
print(arr[1])
arr['age'][0] = 20
print(arr)
arr_d = arr.dtype
print(arr_d.names)
print(arr_d.fields)
a = np.array([(1, 2, 3), (4, 5, 6)], dtype='i8, f4, f8')
a[1] = (7, 8, 9)
print(a)
a = np.zeros(2, dtype='i8, f4, ?, S1')
print(a)
a[:] = 7
print(a)
a[:] = np.arange(2)
print(a)
a = np.zeros(3, dtype=[('a', 'i8'), ('b', 'f4'), ('c', 'S3')])
b = np.ones(3, dtype=[('x', 'f4'), ('y', 'S3'), ('z', 'O')])
b[:] = a
print(b.dtype)
print(a.dtype)
a[:] = 1
print(b)
'''