0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SymPyの関数にまとめて代入したい

Posted at

PythonのSymPyで関数を作り、一気に変数に値を代入したかったのですが、「python sympy subs」などで調べてみても、日本語のテキストがなかなか見つからなかったため、SymPyのドキュメントに書いていたメソッドを紹介しておきます。
#使ってみる

import sympy as sym

x=sym.Symbol("x")
y=sym.Symbol("y")
z=sym.Symbol("z")

f=x*y*z

print(f.subs([(x,1),(y,2),(z,3)]))

#結果

6

引数にはリストで括ってそれぞれをタプルに入れる必要があります。結果は1×2×3で6です。xとyとzに値を入れてみたように、3つ4つと代入する値を入れることも可能です。
以上です。

https://docs.sympy.org/latest/tutorial/basic_operations.html

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?