Hello I'm a beginner programmer and I know there must be a simple way to do this but for some reason can't find the answer. I have two arrays and just want to divide each element by the elements in the other array. for example
a= np.array([2,4,6,8,10,12])
b=np.array([2,1,2,1,2,1])
so that the result is (1,4,3,8,5,12)....
I tried doing this over a for loop :
for i in range(a):
c = a[i]/b[i]
but it doesnt work and gives the error "TypeError: only integer arrays with one element can be converted to an index"
a / bwithout theforloop,numpydoes sensible things with mathematical operations on the whole array.a/bwill work as others have pointed out. The other problem is that you haverange(a)where you should userange(len(a)).