0

我正在使用 oct2py 从 python 执行八度函数,我收到以下错误:

oct2PyError:八度评估错误:错误:二进制运算符'*'未通过'复矩阵'操作为'int64 scalar'实现

在 python 中,我只是调用函数:

from oct2py import octave
results = octave.myOctaveFunction(parameters)

在调试 myOctaveFunction 时,我认为错误在代码中:

slc=interpft(slc, OSF*lines, 1);

在哪里:

编辑:详细追溯:

回溯(最近一次通话最后):

  File "/home/ezaqui/Papyrus/plugins/org.python.pydev_5.1.2.201606231256/pysrc/_pydevd_bundle/pydevd_exec.py", line 3, in Exec
    exec exp in global_vars, local_vars
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/oct2py/dynamic.py", line 96, in __call__
    return self._ref().feval(self.name, *inputs, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/oct2py/core.py", line 369, in feval
    store_as=store_as, plot_dir=plot_dir)
  File "/usr/local/lib/python2.7/dist-packages/oct2py/core.py", line 568, in _feval
    raise Oct2PyError(msg)
Oct2PyError: Octave evaluation error:
error: binary operator '*' not implemented for 'int64 scalar' by 'complex matrix' operations
4

1 回答 1

1

tl;博士:

slc=interpft(slc, double(OSF*lines), 1);

解释:

您正在尝试将复杂矩阵与int64类型相乘。显然,倍频程中没有为这种类型定义乘法运算;它只为双打定义。

>> int64(5) * [1 + 1i]
error: binary operator '*' not implemented for 'int64 scalar' by 'complex scalar' operations

>> double(5) * [1 + 1i]
ans =  5 + 5i

所以这不是一个 oct2py 问题。只需确保在与倍频程函数中的复矩阵相乘之前将其OSF转换为。double

至于为什么首先要与复数相乘,我怀疑 interpft 函数会获取乘法的结果并将复数矩阵相乘。事实证明,在倍频程中,将 int64 与 double 相乘会得到 int64:

>> class(int64(5) * double(5))
ans = int64
于 2017-04-30T00:47:40.637 回答