ich möchte eine pandas Dataframe Zeile mit einer Matrix multiplizieren. Die Matrix ergibt sich aber aus Teilen des Dataframes.
Über eine - wahrscheinlich umständliche - for-Schleife löse ich das Problem zwar, aber ich vermute es gibt eine deutlich schlankere Variante.
Code: Alles auswählen
df = pd.DataFrame({"A": [1, 2, 3, 4],
"B": [5, 6, 7, 8],
"C": [9, 10, 11, 12],
"D": [1, 1, 1, 1]})
l = list()
for index, row in df.iterrows():
l.append(df.loc[index].dot(np.array([[np.sin(df["A"].loc[index]), 0, 0, 0],
[0, np.sign(df["B"].loc[index]), 0, 0],
[0, 0, np.sign(df["C"].loc[index]), 0],
[0, 0, 0, np.tan(df["C"].loc[index])]])))
df[["U", "V", "W", "X"]] = l
print(df)