Question : What does "iNew /= sum(iNew)" do? iNew is an array.

I don't know Python but I'm trying to understand a Python algorithm. It has this one little line I can't figure out.  What does it do?

iNew is an array.
Code Snippet:
1:
iNew /= sum(iNew)
Open in New Window Select All

Answer : What does "iNew /= sum(iNew)" do? iNew is an array.

this variable (believed to be an arry)... iNew divids equal to sum of all the values in iNew..

e.g.

iNew = {1,2,3,4,5}

so.. normal circumstands we can...

iNew / sum(iNew)

to become

{1/15, 2/15, 3/15, 4/15, 5/15}

However, if you are in a loop.. let's say 3 times..

a for loop{
             iNew /= sum(iNew)            
}

The /= means divides equal to

and

sum means adding all the values in that array.
Random Solutions  
 
programming4us programming4us