Numpy 初探SymPy配置

您所在的位置:网站首页 python中的sympy Numpy 初探SymPy配置

Numpy 初探SymPy配置

2022-05-29 08:37| 来源: 网络整理| 查看: 265

初探SymPy配置,IPython中包含一个SymPy配置的样本。SymPy是一个Python的符号计算库。例如,我们可以利用SymPy来化简代数表达式或做微分运算,其功能类似于Mathematica和Maple。显然SymPy是一个有趣的软件,但它不是我们学习NumPy的过程中必须要了解的内容。可以认为本节是一个可选的、有奖励性质的攻略。就像餐后甜点一样,你可以放心地跳过本节,虽然这样做有可能让你错过本章最美妙的一段内容。

文章目录

1 准备工作2 具体步骤 准备工作

使用easy_install或pip安装SymPy:

easy_install sympy sudo pip install sympy 具体步骤 浏览配置文件,其所在位置是~/.ipython/profile_sympy/ipython_config.py。具体内容如下。 c = get_config() app = c.InteractiveShellApp # This can be used at any point in a config file to load a sub config # and merge it into the current one. load_subconfig('ipython_config.py', profile='default') lines = """ from __future__ import division from sympy import * x, y, z, t = symbols('x y z t') k, m, n = symbols('k m n', integer=True) f, g, h = symbols('f g h', cls=Function) """ # You have to make sure that attributes that are containers already # exist before using them. Simple assigning a new list will override # all previous values. if hasattr(app, 'exec_lines'): app.exec_lines.append(lines) else: app.exec_lines = [lines] # Load the sympy_printing extension to enable nice printing of sympy expr's. if hasattr(app, 'extensions'): app.extensions.append('sympyprinting') else: app.extensions = ['sympyprinting']

上面这段代码实现的功能是:

加载默认配置 导入SymPy包 定义符号 使用SymPy配置选项启动IPython,命令如下。 ipython --profile=sympy 使用下图所示命令,展开一个代数表达式。

Numpy 初探SymPy配置



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3