Creating a gradient map of a two-dimensional array

I have a 2D-array that stores the property value of each point as its elements: a f(x,y) = f[x][y]. Now I want to find the gradient of this array. I looked at np.gradient, but it just returns two arrays as a return, first with a derivative in the x direction and second in y.

I want to know how I can use this or any other way to create a gradient map that shows a change in the gradient of a 2D array.
varrayis a 2D array for which I want to create a gradient map. Here is the only thing I can think of right now. I know that there must be a smart way to use x gradientand y gradientgenerated np.gradient(), but I can’t think about it. lxand lyare the sizes x and y of the two-dimensional array.

vgrad = np.gradient(varray)
xgrad = vgrad[0]
x, y = range(0, lx), range(0,ly)
xi, yi = np.meshgrid(x, y)
rbf = scipy.interpolate.Rbf(xi, yi, xgrad)
plt.imshow(v, vmin = np.amin(xgrad), vmax=np.amax(xgrad))
plt.colorbar()
plt.show()  

I want to get basically the second image from the first image. The second image is described as σ = \alpha*grad(varray).

Using the gradient value suggested below.

vgrad = np.gradient(varray)
fulgrad = np.sqrt(vgrad[0]**2 + vgrad[1]**2)
plt.imshow(fulgrad,cmap=plt.get_cmap('hot'), vmin = np.amin(fulgrad),vmax = np.amax(fulgrad))  
plt.colorbar()
plt.show()  

image i get: enter image description here

Am I misinterpreting this from a basic understanding of the equation?

, . : 2D-. : . @Mad Physicist, , , ?

enter image description here enter image description here

+4
1

,

mag = np.sqrt(vgrad[0]**2 + vgrad[1]**2)

mag xgrad, . , -

plt.streamplot(xi, yi, vgrad[0], vgrad[1])

, 3D:

fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(xi, yi, varray)
plt.show()

. Matlab (x, y, z, c) matplotlib? http://matplotlib.org/examples/mplot3d/surface3d_demo.html

+3

Source: https://habr.com/ru/post/1618011/


All Articles