2013-03-27 42 views
1

我有一个MATLAB函数MATLAB功能Python函数转换

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

    indx = hdiv + x + 1; 

    indy = -1*y + vdiv; 

我怎样才能将其转换为Python函数。

回答

3

我可能是错的,但你有没有试过这样:

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

你可以阅读更多的functions defining in python tutorial

1

我想这将是这样的:

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

假设你输入numpy.ndarray形状广播应该工作一样MATLAB。