0

I want to make a plot of gcd function over some region of integers. So basically I want a dot over (x=a,y=b) at z=gcd(x,y) when 0<a<n and 0<b<n.

This code is naive and doesn't work

# make data
X, Y = np.meshgrid(np.linspace(1, 3, 3), np.linspace(1, 3, 3))
#Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
Z = gcd(X,Y)
# plot
fig, ax = plt.subplots()

ax.imshow(Z)

On the other hand the following code give me an array with gcd values over some integers

from fractions import gcd

matrix = [[gcd(i,j) for i in range(20)] for j in range(20)]
print(np.matrix(matrix))

What would be the correct way to obtain a scatter plot of the gcd function?

yngabl
  • 121
  • 1
  • 5
  • Side-note: `fractions.gcd` is deprecated (removed completely as of 3.9). The public API for that functionality is `math.gcd` (available since 3.5), which also happens to be *significantly* faster (the implementation was moved to the C layer on the CPython reference interpreter). – ShadowRanger Jan 17 '23 at 16:23

0 Answers0