Fastest way to count rows in array that match some condition in Julia

Viewed 909

In Julia, I have an array of Booleans like this:

3×5 Array{Bool,2}:
  true  false  true  false   true
  true   true  true   true  false
 false  false  true   true  false

Except I have far more than three rows. What's the fastest/best way to count, say, the number of rows in which the second and fourth column are true, as well as the number of rows in which the second and third column are true? Right now I have something like this, where N is the number of rows:

num_2and3true = 0
num_2and4true = 0
for i = 1:N                                                                                                            
  if m[i,2] == 1                                                                                                        
    if m[i,3] == 1                                                                                                         
      num_2and3true += 1                                                                                                  
    end                                                                                                                  
    if m[i,4] == 1                                                                                                         
      num_2and4true += 1                                                                                                 
    end                                                                                                                
  end                                                                                                                
end 

Is there a faster way to do this? I have a hunch that the way I'm doing it is too simple to be the best way. Thanks....

3 Answers
Related