+ 1
how i get the index of element in numpy array?
hi i want too write a proggram for heat transfer in this stage of my proggram i want to know that a elemet is on boundary or not? and now i write this i should konw the index of my element to put it in my on_line() function thank you ``` import numpy as np hg=np.zeros([13,29]) def conv(h,t2,t1): return h*.002*(t2-t1) def cond(k,t2,t1): return k*(t2-t1) def on_line(i,j): if j==0: return 'top' if i==0: return 'left' if j==12: return 'down' if i==28: return 'right' for i in hg: for j in hg: c=on_line()
1 Odpowiedź
0
If i understood correctly what you want, you can use np.indices which will get you arrays of given shape filled with the indices along each dimension.
https://numpy.org/doc/stable/reference/generated/numpy.indices.html