Relative Content

Tag Archive for array

Count true array elements

In my code (Python+numpy or Matlab, but issue can apply to any array programming language), I often need to count the number of elements in an array where the elements are true. Usually, I implement this as sum(x>0.5), but this may be considered improper. See Is it correct to add booleans in order to count the number of true values in a vector?. Numpy has count_nonzero, but if there is no special-purpose function, what would be the proper way to write this?

Array Multiplication and Division

I came across a question that (eventually) landed me wondering about array arithmetic. I’m thinking specifically in Ruby, but I think the concepts are language independent.

Array Multiplication and Division

I came across a question that (eventually) landed me wondering about array arithmetic. I’m thinking specifically in Ruby, but I think the concepts are language independent.

Array Multiplication and Division

I came across a question that (eventually) landed me wondering about array arithmetic. I’m thinking specifically in Ruby, but I think the concepts are language independent.