Wie bekomme ich mit numpy (Phython) ein dyadisches Produkt hin?

1 Antwort

was du suchst ist np.outer()

import numpy as np

spaltenvec = np.array([1,2,3])
zeilenvec  = np.array([4,5,6])

matrix = np.outer(zeilenvec, spaltenvec)

Herrdings 
Fragesteller
 14.08.2019, 13:52

okay danke, das funktioniert schon mal. Nun möchte ich aber noch, dass er eine 4x4-Matrix mit einem 4 Komponenten Spaltenvektor multipliziert und dabei wieder ein Spaltenvektor herauskommt.... im Moment ergibt das aber eine 4x4-Matrix

0
Herrdings 
Fragesteller
 14.08.2019, 15:06
@Explowox

das mache ich ja die ganze Zeit, aber dann kommt eine 4x4-Matrix heraus

0
Herrdings 
Fragesteller
 14.08.2019, 15:10
@Herrdings
A=  np.array( ((0,1,0,0), (0, -26,-5,0.75), (0,0,0,1), (0,90,47.6854,-2.5)) )    # 4x4-Matrix
B=  np.array ( ((1), (5), (-8), (2)) )   # 4x1 Spaltenvektor
produkt= np.dot(A,B)
0
Explowox  14.08.2019, 15:15
@Herrdings

Wenn ich deinen Code ausführe und mir produkt printe kommt bei mir [  5.     -88.5      2.      63.5168]  raus. Das willst du doch?

1
Herrdings 
Fragesteller
 14.08.2019, 15:25
@Explowox

ich habe gerade einen Fehler entdeckt. Eine Matrix bekommt in einer Schleife eine andere Variable zugewiesen und ich habe den Print-Befehl in die Schleife gelegt.... es funktioniert

1