プログラム一覧に戻る
import numpy as np
arr1 = np.array([1, 2, 3, 4]) # リストからndarrayを生成し、arr1という名前を付ける
print("arr1 =", arr1)
arr2 = np.sin(arr1)
print("np.sin(arr1) =", arr2) # [ 0.84147098 0.90929743 0.14112001 -0.7568025 ]
arr2 = np.cos(arr1)
print("np.cos(arr1) =", arr2) # [ 0.54030231 -0.41614684 -0.9899925 -0.65364362]
arr2 = np.tan(arr1)
print("np.tan(arr1) =", arr2) # [ 1.55740772 -2.18503986 -0.14254654 1.15782128]
arr2 = np.exp(arr1)
print("np.exp(arr1) =", arr2) # [ 2.71828183 7.3890561 20.08553692 54.59815003]
arr2 = np.log(arr1)
print("np.log(arr1) =", arr2) # [0. 0.69314718 1.09861229 1.38629436]
arr2 = np.sinh(arr1)
print("np.sinh(arr1) =", arr2) # [ 1.17520119 3.62686041 10.01787493 27.2899172 ]
arr2 = np.cosh(arr1)
print("np.cosh(arr1) =", arr2) # [ 1.54308063 3.76219569 10.067662 27.30823284]
arr2 = np.tanh(arr1)
print("np.tanh(arr1) =", arr2) # [0.76159416 0.96402758 0.99505475 0.9993293 ]
arr2 = np.sqrt(arr1) # arr2 = arr1 ** 0.5 と等価
print("np.sqrt(arr1) =", arr2) # [1. 1.41421356 1.73205081 2. ]
arr2 = -arr1
print("-arr1 =", arr2) # [-1 -2 -3 -4]
arr2 = np.abs(-arr1) # 要素ごとの絶対値
print("np.abs(-arr1) =", arr2) # [1 2 3 4]