Während mein Problem mit der sympy github Problem here verknüpft scheint, scheint es entweder nicht direkt verwandt oder bleibt ein offenes, ungelöstes Problem (ab 2012).sympy Matrizen in einem sympy Matrix bleibt bei Substitution nicht bewertet
Mein Problem ist, dass ich eine 'Matrix' (wirklich, es ist nur ein Vektor, aber ist meine einzige Option, wie Sympy mit Dingen handelt) innerhalb meiner Matrix durch ein Symbol dargestellt, dass, wenn substituiert, zeigt eine Matrix anstatt es zu bewerten.
Unten ist ein Beispiel Codeblock, der diese demonstrieren: in jedes Element unterteilt werden
import numpy as np
import sympy
x = np.random.rand(15, 3)
l_syms = sympy.MatrixSymbol('l', 1, 3)
m = sympy.Matrix(x/l_syms)
m.subs({l_syms:sympy.Matrix([[1,1,1]])})
Jeder Wert in der matrix
[[1,1,1]] der m
Matrix sollte, aber die Die Matrix bleibt unverändert, wobei die Indexnotation erhalten bleibt.
Matrix([
[ 0.98979011265311*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.833576329284127*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.575808048824554*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.523263044342704*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.320197709246721*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.592365354846089*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.943288501064919*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.996020450969247*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.964522394691641*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.763752929521655*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.690054409108757*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.417629855595703*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.213578356927868*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.362782611339912*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.892921288169683*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.068921237699985*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.244310349677818*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.977494896836049*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[0.0169721915631557*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.254316922886399*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.682785271511585*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.768287921847173*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.679243253034139*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.790710466097621*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.892115183428169*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.988514816033581*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.537769900907173*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.275725750770885*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.928279364723852*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.18023576064915*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.71421202332017*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.663585719630706*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.43460735199406*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.770814091341355*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.0650430822905173*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.0845773234523002*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[0.0398441324212175*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.0358479090409692*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.0801076763216808*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.89937521111821*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.21500916688666*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.661216039738327*Matrix([[1, 1, 1]])[0, 2]**(-1)],
[ 0.866641224226343*Matrix([[1, 1, 1]])[0, 0]**(-1), 0.0506005171711028*Matrix([[1, 1, 1]])[0, 1]**(-1), 0.791277139679317*Matrix([[1, 1, 1]])[0, 2]**(-1)]])
ich einen Weg, nicht in der Lage sein scheinen zu finden, um bewerten diese alle Matrix-Objekte und deren Indizes - das einzige, was der Ferne über die Github Problem verknüpft verwandt war, aber xreplace
ist mit für meine Absichten noch weniger optimal/korrekt, da es das Symbol an Ort und Stelle belässt, anstatt die Matrix zu ersetzen.
Jede Hilfe wird sehr geschätzt.
bewerten Dies ist ein relevantes Thema https://github.com/sympy/sympy/issues/2962 – asmeurer