I am trying to build a meshgrid in order to compute an interpolation. I inspire myself from this example. My function is the following:
def oscillatory_(a,b,d,w=w,c=c):
x = np.array([a,b,d])
return np.cos(2*math.pi*w[0,0] + np.sum(c.T*x, axis = 1))
Which I call through:
data = oscillatory_(*np.meshgrid(a,b,d,indexing='ij', sparse=True))
Where
a = grid_dim[:,0]
b = grid_dim[:,1]
d = grid_dim[:,2]
are just some values taken from grid_dim which is a numpy n-array
When trying to run the code, I get the following error:
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 9, in <module>
File "<input>", line 3, in f
AttributeError: 'numpy.ndarray' object has no attribute 'cos'
I really don't understand why is he assigning cos as an attribute and not a function, because if I run the function oscillatory outside the *np.meshgrid() everything is ok.
Also, I have played with the toy example from the link below adding a np.cos function and everything works fine. The problem is in my function and I am not able to figure where.
I am doing this in order to compute an interpolation afterwards through:
my_interpolating_function = RegularGridInterpolator((a,b,d), data)
Any help would be highly appreciated on that one. Thank you very much
np.cosan array with object dtype, it iterates through the array, trying to delegate the task to ancosmethod for each item. I suspect then that you've passed an array of arrays tocos. Examine thecosargument for shape and dtype.