ブロードキャスト

次のコードで空欄になっている行に入る適切な選択肢を 1 ~ 3 から選び、下記の設問に答えてください.

Q1:変数 arr_2d の各要素に各行のインデックス番号を掛けてください.
また、各行のインデックス番号を表す5 行 1 列の配列を用意してください.

import numpy as np

arr_2d = np.arange(25).reshape(5, 5)

# Q1
y = np.arange(5).reshape(5, 1)
print(arr_2d * y)

[Q1の選択肢]
1.
y = np.arange(5).reshape(1, 5)
print(arr_2d * y)
2.
y = np.arange(5).reshape(5, 1)
print(arr_2d * y)
3.
y = np.arange(5).reshape(5, 1)
print(np.dot(arr_2d, y))

Leave a comment

Your email address will not be published. Required fields are marked *