Apply Function to Python Meshgrid



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. ]
Updated on: 2021-05-08T09:25:51+05:30

569 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements