Как получить скалярное произведение соответствующих строк в двух массивах? ⇐ Python
Как получить скалярное произведение соответствующих строк в двух массивах?
How do I perform this without using for loops and just numpy functions?
import numpy as np arr_x = np.array([[1,2,3], [4,5,6]]) arr_y = np.array([[1,2,3], [4,5,6]]) res = [] for x, y in zip(arr_x, arr_y): res.append(np.dot(x, y)) np.array(res) # array([14, 77]) I tried tensordot with axes=1, but that throws a shape mismatch error.
Источник: https://stackoverflow.com/questions/781 ... two-arrays
How do I perform this without using for loops and just numpy functions?
import numpy as np arr_x = np.array([[1,2,3], [4,5,6]]) arr_y = np.array([[1,2,3], [4,5,6]]) res = [] for x, y in zip(arr_x, arr_y): res.append(np.dot(x, y)) np.array(res) # array([14, 77]) I tried tensordot with axes=1, but that throws a shape mismatch error.
Источник: https://stackoverflow.com/questions/781 ... two-arrays
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение