Dividing arrays in IDL and sum over array elements

202 Views Asked by At

I was wondering how to divide two arrays

a = [1,2,3,4,5]
b = [2,4,6,8,15]

to get

a/b = [0.5,0.5,0.5,0.5,0.3]

Thanks in advance for the help.

2

There are 2 best solutions below

0
mgalloy On

Most operations in IDL are performed element-wise, so doing c = a / b will do what you want here.

0
user22265185 On

Just express the arrays as floating variables or doubles, then you will get the desired results. Otherwise, the results will come as 0.0 as it rounds up to the lowest integer. I hope it will work.