2013-03-27 81 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。