Tsallaka zuwa abun ciki
Justice Tech School

Grids with meshgrid

meshgrid builds coordinate matrices from vectors, handy for plotting functions of two variables.

Example
import numpy as np
x = np.array([1, 2, 3])
y = np.array([10, 20])
X, Y = np.meshgrid(x, y)
print(X)
print(Y)
print(X + Y)

Result

[[1 2 3]
 [1 2 3]]
[[10 10 10]
 [20 20 20]]
[[11 12 13]
 [21 22 23]]

Exercise

Build coordinate grids.

np.(x, y)

Quiz Test

What is meshgrid for?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.