Counting elements of a matrix which satisfy a given property

### 14.3.12 Counting elements of a matrix which satisfy a given property

The count applies a function to the elements of a matrix or list and adds up the obtained values. In particular, if the function returns a boolean, then count returns the number of elements satifying the property that the function tests for.

- count takes two arguments:
  - f, a real-valued function.
  - A, a matrix or a list.
- count(f,A) returns the sum of the function f applied to the elements of A.

#### Examples

count(x->x,[[2,12],[45,3],[7,78]])

147 |  |  |  |  |  |  |  |  |  |

Indeed, 2+12+45+3+7+78=147.

count(x->x<10,[[2,12],[45,3],[7,78]])

3 |  |  |  |  |  |  |  |  |  |