Ich möchte das Element-weise äußere Produkt von zwei 2d-Arrays in numpy tun.numpy elementwise äußere Produkt
A.shape = (100, 3) # A numpy ndarray
B.shape = (100, 5) # A numpy ndarray
C = element_wise_outer_product(A, B) # A function that does the trick
C.shape = (100, 3, 5) # This should be the result
C[i] = np.outer(A[i], B[i]) # This should be the result
Eine naive Implementierung kann Folgendes.
tmp = []
for i in range(len(A):
outer_product = np.outer(A[i], B[i])
tmp.append(outer_product)
C = np.array(tmp)
Eine bessere Lösung, die vom Stapelüberlauf inspiriert ist.
Ich bin auf der Suche nach einer vektorisierten Implementierung, die die for-Schleife los wird. Hat jemand eine Idee? Vielen Dank!
Für das, was es wert ist, 'np.multiply.outer (a, b)' ist anders als 'np.outer ', formgebend' 100, 3, 100, 5' – Eric