Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
matlab函数到python函数的转换_Python_Matlab_Function - Fatal编程技术网

matlab函数到python函数的转换

matlab函数到python函数的转换,python,matlab,function,Python,Matlab,Function,我有一个matlab函数 function [indx, indy] = coord2index(hres, vres, hdiv, vdiv, x, y) indx = hdiv + x + 1; indy = -1*y + vdiv; 如何将其转换为python函数。我想它应该是这样的: def coord2index(hres, vres, hdiv, vdiv, x, y): indx = hdiv + x + 1 indy = -1*y + vdiv retu

我有一个matlab函数

function [indx, indy] = coord2index(hres, vres, hdiv, vdiv, x, y)

  indx = hdiv + x + 1;

  indy = -1*y + vdiv;

如何将其转换为python函数。

我想它应该是这样的:

def coord2index(hres, vres, hdiv, vdiv, x, y):
  indx = hdiv + x + 1
  indy = -1*y + vdiv
  return indx, indy

假设输入为numpy.ndarray,则形状广播的工作原理应与matlab相同

我想应该是这样的:

def coord2index(hres, vres, hdiv, vdiv, x, y):
  indx = hdiv + x + 1
  indy = -1*y + vdiv
  return indx, indy

假设输入为numpy.ndarray,则形状广播的工作原理应与matlab相同

我可能错了,但你试过这个吗:

def coord2index(hres, vres, hdiv, vdiv, x, y):
    return hdiv + x + 1, (-1) * y + vdiv

你可以在

上阅读更多内容。我可能错了,但你试过这个吗:

def coord2index(hres, vres, hdiv, vdiv, x, y):
    return hdiv + x + 1, (-1) * y + vdiv
你可以阅读更多关于