6.45.12 Counting the elements of a matrix satisfying a property: count
The count applies a function to the elements of a matrix or
list and adds the result. Hence, if the function is a boolean function, then
count will count 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.
-
Input:
count(x->x,[[2,12],[45,3],[7,78]])
Output:
Indeed: 2+12+45+3+7+78=147.
- Input:
count(x->x<10,[[2,12],[45,3],[7,78]])
Output: