How do I apply some function to a Python meshgrid?

PythonMatplotlibServer Side ProgrammingProgramming

Meshgrid − Coordinate matrices from coordinate vectors.

Let's take an example to see how we can apply a function to a Python meshgrid. We can consider two lists, x and y, using numpy vectorized decorator.

Example

import numpy as np
@np.vectorize
def foo(a, b):
return a + b
x = [0.0, 0.5, 1.0]
y = [0.0, 1.0, 8.0]
print("Function Output: ", foo(x, y))

Output

Function Output: [0. 1.5 9. ]
Published on 08-May-2021 09:21:20