Previous Up Next

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.

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           

Previous Up Next