python - Create layer of any shape in NumPy -
i create layered model this:
import numpy np import pandas pd import matplotlib.pyplot plt      = np.full((9,10),1) a[:5,] = 1 a[5:10,] = 2 print(a) plt.imshow(a)  >>> output: [[1 1 1 1 1 1 1 1 1 1]  [1 1 1 1 1 1 1 1 1 1]  [1 1 1 1 1 1 1 1 1 1]  [1 1 1 1 1 1 1 1 1 1]  [1 1 1 1 1 1 1 1 1 1]  [2 2 2 2 2 2 2 2 2 2]  [2 2 2 2 2 2 2 2 2 2]  [2 2 2 2 2 2 2 2 2 2]  [2 2 2 2 2 2 2 2 2 2]] the result of plt.imshow() shown here.
lets consider have 2 vectors:
x = np.linspace(0,10,10) z = np.random.uniform(0, 9, size=(1,9)).round(0) where x row, , z column (coordinates if keep simple).
how change numpy array in way, assign value=10 corresponding pairs of x , z (x[i],z[i]) = 1? in end can have this.
here example of how index numpy arrays using iterables:
import numpy np import matplotlib.pyplot plt      = np.full((10,10),1)  x = np.arange(10) z = np.random.randint(0, 10, size=(1,10))  a[x,z] = 2  plt.imshow(a) plt.show() note how use astype(int) instead of round (edit: better use randint start -- kazemakase comment) , how adjusted range of a. replaced linspace arange, latter guaranteed produce integers.
the result looks this:

Comments
Post a Comment