Excluding NAN entries when summing an array

R

RS

Hi all, what is a safe and efficient way to sum the contents of an array
or a matrix, skipping any possible NANs or INFs?

Thanks,
RS
 
J

Jacek Dziedzic

RS said:
Hi all, what is a safe and efficient way to sum the contents of an array
or a matrix, skipping any possible NANs or INFs?

The NaN has this queer property that if x is a NaN, then
x!=x. Therefore you may skip NaNs with something like

for(...) {
if(myarray!=myarray) // skip this entry, a NaN
}


HTH,
- J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top