If you have an array of Y items, and want to count the items that are not zero

for x in Array
 if (x!=0)
    sum = sum +1

How can we substitute this loop with a Summation equation using sigma notation?

  • 2
    I'm not sure that this is the correct site for your question. Are you wanting to find a more efficient way to code your loop (definitely off topic)? Do you have some mathematical notation that you'd like to change into TeX (definitely on topic, but we'd like to see the notation)? Or are you wanting to figure out how to represent the expression in math, and then convert that into TeX? That's close to on-topic, I suppose. – Teepeemm Jun 20 at 0:01
  • 1
    is this a question about LaTeX? it does not appear to be? – David Carlisle Jun 20 at 0:01
  • @Teepeemm I want to write it in math and latex – Thomas Lee Jun 20 at 1:36

This question is slightly off-topic, because it is asking about math notation. Anyway, given that your array is represented by A you can find the number of non-zero elements S using the Kronecker delta.


    S = \sum_{x \in A} (1 - \delta_{x,0})


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.