python无法从八度函数中解开返回的值

发布于 2025-01-28 06:25:00 字数 643 浏览 2 评论 0原文

我在八度中具有称为dofft.m的函数,定义为:

function [Rx1,Rx2,fbins]=doFFT(file)

此函数按预期返回3行向量运行。

在Python中,我已经进口了Oct2py,

from oct2py import octave

我通过以下方式称呼此八度函数:

RX1,RX2,fbins=octave.doFFT(file)

我遇到一个错误,上面写着“ ValueError:不足以解开包装(预期3,获得1)”

作为测试,我重新定义了八度的功能以返回1个值,而是在python中称其为:

RX1=octave.doFFT(file)

这很好。

因此,问题似乎是让Python了解八度的回报格式。 我尝试将功能称为例如

[RX1, RX2, fbins]=octave.doFFT(file)
(RX1, RX2, fbins)=octave.doFFT(file)

,但仍然会遇到相同的错误。

如何格式化函数调用或八度的输出,以便python“理解”有3个项目正在返回?

I have a function called doFFT.m in Octave, defined as:

function [Rx1,Rx2,fbins]=doFFT(file)

this function runs as expected returning 3 row vectors.

In Python, I have oct2py imported,

from oct2py import octave

and I call this Octave function via:

RX1,RX2,fbins=octave.doFFT(file)

I get an error that says "ValueError: not enough values to unpack (expected 3, got 1)"

As a test I redefined the function in Octave to only return 1 value, and instead called it in Python as :

RX1=octave.doFFT(file)

and this worked fine.

So, the issue seems to be with having Python understand the return format from Octave.
I've tried calling the function as

[RX1, RX2, fbins]=octave.doFFT(file)
(RX1, RX2, fbins)=octave.doFFT(file)

for example, but still get either the same error.

How do I format the function call or the output from Octave, so that Python "understands" that there are 3 items being returned?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赤濁 2025-02-04 06:25:00

oct2py python桥要求在功能调用中明确表示返回值的预期数,例如。

RX1,RX2,fbins=octave.doFFT(samples, nout=3)

指定该函数返回3个值(在这种情况下为Numpy数组)。
当函数不返回任何内容时,必须称呼它表示它返回0个参数,即:

octave.foobar(in_arg, nout=0).

谢谢@tasos papastlyianou在他的评论中链接了Oct2py的文档。

the oct2py python bridge requires that the expected number of returned values to be explicitly expressed in the function call, for eg.

RX1,RX2,fbins=octave.doFFT(samples, nout=3)

specifies that the function returns 3 values (or numpy arrays in this case).
When a function doesn't return anything, it must be called indicating that it returns 0 arguments, ie:

octave.foobar(in_arg, nout=0).

Thank you to @Tasos Papastlyianou for linking the oct2py's documentation in his comment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文