微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在python中使用模除的numpy.poly1d找到方程的根

如何解决在python中使用模除的numpy.poly1d找到方程的根

我已经使用 2021-07-29T13:10:44.686327+00:00 app[worker.1]: Failed to import ahead-of-time-compiled modules. 2021-07-29T13:10:44.686380+00:00 app[worker.1]: This is expected on first import. 2021-07-29T13:10:44.686381+00:00 app[worker.1]: Compiling modules and trying again. 2021-07-29T13:10:44.686388+00:00 app[worker.1]: This might take a minute. 2021-07-29T13:10:45.932417+00:00 app[worker.1]: Traceback (most recent call last): 2021-07-29T13:10:45.934406+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pymatting_aot/cc.py",line 36,in <module> 2021-07-29T13:10:45.934847+00:00 app[worker.1]: import pymatting_aot.aot 2021-07-29T13:10:45.934974+00:00 app[worker.1]: ModuleNotFoundError: No module named 'pymatting_aot.aot' 2021-07-29T13:10:45.935002+00:00 app[worker.1]: 2021-07-29T13:10:45.935006+00:00 app[worker.1]: During handling of the above exception,another exception occurred: 2021-07-29T13:10:45.935006+00:00 app[worker.1]: 2021-07-29T13:10:45.935036+00:00 app[worker.1]: Traceback (most recent call last): 2021-07-29T13:10:45.935074+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/runpy.py",line 197,in _run_module_as_main 2021-07-29T13:10:45.935342+00:00 app[worker.1]: return _run_code(code,main_globals,None,2021-07-29T13:10:45.935377+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/runpy.py",line 87,in _run_code 2021-07-29T13:10:45.935988+00:00 app[worker.1]: exec(code,run_globals) 2021-07-29T13:10:45.936017+00:00 app[worker.1]: File "/app/Rimuru/__main__.py",line 3,in <module> 2021-07-29T13:10:45.936212+00:00 app[worker.1]: import Rimuru.modules 2021-07-29T13:10:45.936247+00:00 app[worker.1]: File "/app/Rimuru/modules/__init__.py",line 1,in <module> 2021-07-29T13:10:45.936459+00:00 app[worker.1]: from Rimuru.modules import (_u,pm,scraper,tag_log,utils,songs,jikan_flex,rem_bg) 2021-07-29T13:10:45.936489+00:00 app[worker.1]: File "/app/Rimuru/modules/rem_bg.py",in <module> 2021-07-29T13:10:45.936679+00:00 app[worker.1]: from rembg.bg import remove 2021-07-29T13:10:45.936711+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/rembg/bg.py",line 6,in <module> 2021-07-29T13:10:45.937736+00:00 app[worker.1]: from pymatting.alpha.estimate_alpha_cf import estimate_alpha_cf 2021-07-29T13:10:45.937764+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pymatting/__init__.py",line 2,in <module> 2021-07-29T13:10:45.937967+00:00 app[worker.1]: import pymatting_aot.cc 2021-07-29T13:10:45.937997+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pymatting_aot/cc.py",line 54,in <module> 2021-07-29T13:10:45.938208+00:00 app[worker.1]: compile_modules() 2021-07-29T13:10:45.938238+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pymatting_aot/cc.py",line 8,in compile_modules 2021-07-29T13:10:45.938622+00:00 app[worker.1]: cc = CC("aot") 2021-07-29T13:10:45.938654+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/numba/pycc/cc.py",line 65,in __init__ 2021-07-29T13:10:45.939041+00:00 app[worker.1]: self._toolchain = Toolchain() 2021-07-29T13:10:45.939084+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/numba/pycc/platform.py",line 78,in __init__ 2021-07-29T13:10:45.940654+00:00 app[worker.1]: self._raise_external_compiler_error() 2021-07-29T13:10:45.940688+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/numba/pycc/platform.py",line 121,in _raise_external_compiler_error 2021-07-29T13:10:45.940940+00:00 app[worker.1]: raise RuntimeError(msg) 2021-07-29T13:10:45.941020+00:00 app[worker.1]: RuntimeError: Attempted to compile AOT function without the compiler used by `numpy.distutils` present. If using conda try: 2021-07-29T13:10:45.941021+00:00 app[worker.1]: 2021-07-29T13:10:45.941045+00:00 app[worker.1]: #> conda install gcc_linux-64 gxx_linux-64 2021-07-29T13:10:46.563596+00:00 heroku[worker.1]: Process exited with status 1 2021-07-29T13:10:46.666541+00:00 heroku[worker.1]: State changed from up to crashed 和一些任意系数 numpy.poly1d 创建了一个多项式对象,以便我可以在给定的 (a,b,c) 处找到方程 ax^2 + bx + c = y0 的根。原则上,这可以通过调用 y0 对象的 root 方法轻松完成。

唯一的问题是我试图解决的实际方程与上面写的相同,但模除以 2π 这对应于当多项式模除以 2π 等于 {{1} },(或为poly1d找到y0

但是,我似乎无法将此模运算符应用于 x 对象。

有没有办法使用 NumPy 做到这一点?

这里有几行代码

y = (ax^2 + bx + (c-yo)) [2*pi]

解决方法

看来您可以使用 np.mod 代替 %。 唯一的问题是 np.mod 在这种情况下返回一个数组,而不是一个 poly1d 对象。

,

实际上,通过简单地将 2kπ 添加到多项式的 0 阶项,并扫描 k 的几个值,直到得到包含在正确范围内的根,我实际上设法解决了这个问题。

不理想,但有效。尽管如此,仍然对聪明的做法持开放态度!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。