NumPy③ (ベクトルの累乗、平方根)

ベクトルの累乗

NumPyで、累乗は power(配列, 指数) で求めることができます。

また、演算子の ** で求めることも可能です。

[Google Colaboratory]

1
2
3
import numpy as np
x = np.array([1, 2, 3, 4, 5], dtype = np.float)
np.power(x, 2)

[実行結果]

[Google Colaboratory]

1
x ** 2

[実行結果]


ベクトルの平方根

NumPyで、平方根は sqrt(x) で求めることができます。

[Google Colaboratory]

1
2
x = np.array([1, 2, 3, 4, 5], dtype = np.float)
np.sqrt(x)

[実行結果]