プログラム一覧に戻る
import numpy as np
arr1 = np.array([1, 2, 3, 4]) # リストからndarrayを生成し、arr1という名前を付ける
print("arr1 =", arr1)
arr2 = np.arange(5, 1, -1) # [5, 4, 3, 2]というndarrayを生成し、arr2という名前を付ける
print("arr2 =", arr2)
arr3 = arr1 + arr2
print("arr1 + arr2 =", arr3) # [6 6 6 6]
arr3 = arr1 - arr2
print("arr1 - arr2 =", arr3) # [-4 -2 0 2]
arr3 = arr1 * arr2
print("arr1 * arr2 =", arr3) # [5 8 9 8]
arr3 = arr1 / arr2
print("arr1 / arr2 =", arr3) # [0.2 0.5 1. 2. ]
arr3 = arr1 ** arr2
print("arr1 ** arr2 =", arr3) # [ 1 16 27 16]
arr3 = arr1 @ arr2 # 2つのndarrayの内積
print("arr1 @ arr2 =", arr3) # 30