La mia domanda è molto intuitiva negli array ma non nelle matrici. Come posso multiplo un elemento dalla riga di una matrice in tutta la fila equivalente in altra matrice. Supponiamo di avere:
x = np.matrix([[1], [2]])
y = np.matrix([[3, 4], [5, 6]])
e voglio ottenere come risultato:
[[3, 4], [10, 12]
o in un modo più leggibile:
x = 1
2
y = 3 4
5 6
e voglio ottenere come risultato:
3 4
10 12
risposte:
3 per risposta № 1AGGIORNARE: Puoi usare np.multiply () funzione:
In [57]: x
Out[57]:
matrix([[1],
[2]])
In [58]: y
Out[58]:
matrix([[3, 4],
[5, 6]])
In [59]: np.multiply(y, x)
Out[59]:
matrix([[ 3, 4],
[10, 12]])
VECCHIA risposta:
funzionerebbe fuori dalla scatola se tu usassi np.array
invece di np.matrix
:
In [44]: xx = np.array([[1], [2]])
In [45]: yy = np.array([[3, 4], [5, 6]])
In [46]: xx
Out[46]:
array([[1],
[2]])
In [47]: yy
Out[47]:
array([[3, 4],
[5, 6]])
In [48]: yy * xx
Out[48]:
array([[ 3, 4],
[10, 12]])
Questa risposta potrebbe aiutare a capire la differenza tra np.array
e np.matrix