matlab函数用于python函数转换

时间:2013-03-27 03:43:22

标签: python matlab function

我有一个matlab函数

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

  indx = hdiv + x + 1;

  indy = -1*y + vdiv;

如何将其转换为python函数。

2 个答案:

答案 0 :(得分:3)

我错了,但你试过这个:

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

您可以在functions defining in python tutorial

上阅读更多内容

答案 1 :(得分:1)

我猜它会是这样的:

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

假设您的输入为numpy.ndarray,形状广播应与matlab相同。