import numpy as np
# 最初に配列を作る
a = np.array([1,2,3,4,5])
print(a)
print(type(a))
# 2次元配列を作る
b = np.array([[1,2,3],[4,5,6]])
print(b)
# np.zeros()関数で、0ゼロで配列を作る np.ones()関数だと1で配列を作る
print(np.zeros(10))
print(np.zeros((3,2)))
# np.arange()は連番で配列を作成
print(np.arange(5))
print(np.arange(2, 9))
print(np.arange(5,8,0.5))
# 行列計算
a = np.array([1, 2, 3, 4, 5])
b = a * 2
print(b)
x = np.arange(10)
y = 3 * x + 5
print(y)
# shapeプロパティで、配列の次元数を調べる
a = np.array([[1,2,3], [4,5,6]])
print(a.shape)
b = np.array([[1,2,3], [4,5,6], [7,8.9]])
print(b.shape)
# flatten()メソッドで次元数を変換する
a = np.array([[1,2,3],[4,5,6]])
print("a=", a)
b = a.flatten()
print("b=", b)
# reshape()メソッドで、配列を任意の形状に変換
a = np.array([[1,2,3],[4,5,6]])
print(a)
print(a.reshape(3,2))
# 配列要素へのアクセス
v = np.array([[[1,2,3],[4,5,6],[7,8,8]]])
a = v[0]
b = v[1:]
c = v[: , 0]
print("a=", a)
print("b=", b)
print("c=", c)