2

https://zulko.wordpress.com/2012/04/15/symbolic-matrix-differentiation-with-sympy/を Python35 でテストしていますが、次のエラーが発生しました。

Traceback (most recent call last):
  File "D:\Program Files\JetBrains\PyCharm 2016.1\helpers\pydev\pydev_run_in_console.py", line 71, in <module>
    globals = run_file(file, None, None)
  File "D:\Program Files\JetBrains\PyCharm 2016.1\helpers\pydev\pydev_run_in_console.py", line 31, in run_file
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\Program Files\JetBrains\PyCharm 2016.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/programs/python/wcf/test2/my.py", line 134, in <module>
    matPrint(  expand( expand( matDiff(H,X) ) ) )
  File "D:/programs/python/wcf/test2/my.py", line 64, in matDiff
    return  MATRIX_DIFF_RULES[expr.__class__](expr,symbols)
  File "D:/programs/python/wcf/test2/my.py", line 54, in <lambda>
    Mul :  lambda e,s : Mul(matDiff(e.args[0],s),Mul(*e.args[1:]))
  File "D:/programs/python/wcf/test2/my.py", line 64, in matDiff
    return  MATRIX_DIFF_RULES[expr.__class__](expr,symbols)
  File "D:/programs/python/wcf/test2/my.py", line 52, in <lambda>
    Symbol : lambda e, s: d(e) if (e in s) else 0,
TypeError: argument of type 'Symbol' is not iterable
4

1 に答える 1

3

私の推測では、コードは古いバージョンの SymPy に対して書かれており、x in sin(x). 現在、これは許可されておらず、使用する必要がありますhas。したがって、交換は

Symbol : lambda e, s: d(e) if s.has(e) else 0,
于 2016-06-08T16:36:48.580 に答える