Умножение в массиве numpyPython

Программы на Python
Гость
Умножение в массиве numpy

Сообщение Гость »


I'm trying to multiply each of the terms in a 2D array by the corresponding terms in a 1D array. This is very easy if I want to multiply every column by the 1D array, as shown in the numpy.multiply function. But I want to do the opposite, multiply each term in the row. In other words I want to multiply:

[1,2,3] [0] [4,5,6] * [1] [7,8,9] [2] and get

[0,0,0] [4,5,6] [14,16,18] but instead I get

[0,2,6] [0,5,12] [0,8,18] Does anyone know if there's an elegant way to do that with numpy? Thanks a lot, Alex

Вернуться в «Python»