I'm coding a function taking in an array of shape (2,) and performing a simple operation:
def simpfunc(x):
return x[1]-x[0]
I would now like to evaluate this function over a large quantity of values, created by a meshgrid. To this end, I apply the following (as I wish to avoid for loops):
newfunc=vectorize(simpfunc)
G=array(meshgrid(linspace(0,5,5),linspace(0,5,5))).T
The array G is a large matrix (or I suppose a tensor), where each individual entry is an array containing two values. I would like to evaluate simpfunc over these (2,) arrays, producing a matrix with the calculated values. So I do the following:
newfunc(G)# IndexError: invalid index to scalar variable.
I have previously used vectorize to evaluate a function over vectors, but now I suppose the matrix, along with the sub-matirces are giving me some trouble.
Any ideas?