import numpy as np

# 1. 2x2のndarrayを定義
w = np.array([[1, 2],
              [3, 4]])

# 2. 各要素を2乗する (Element-wise)
# 結果: [[1, 4], [9, 16]]
w_squared = w ** 2

# 3. 全要素を合計してスカラーにする
# 計算: 1 + 4 + 9 + 16 = 30
total_norm = np.sum(w_squared)

print(f"元の配列 w:\n{w}")
print(f"2乗した配列 w**2:\n{w_squared}")
print(f"合計値 total_norm: {total_norm}")
print(f"型: {type(total_norm)}") # <class 'numpy.int64'> (スカラー)