I'm trying to find a way to count the number of rows in a matrix that contains specific elements in specific cells.
For example, suppose I have the following matrix
Data={{1,1,1,1},{1,1,0,1},{1,0,0,1},{0,1,0,0},{1,0,0,0},{1,0,1,0},{1,1,1,1},{0,1,0,0}}
What I want to find is the number of rows that is consistent with the following list:
list1={1,Null,Null,1}
So, in the data, {{1,1,1,1},{1,1,0,1},{1,0,0,1},{1,1,1,1}}
is consistent with the list1
, so the output should be 4.
Another example is if list2={1,1,1,1}
, then the output should be 2.
If list3={1,Null,Null,Null}
, then we should have 6 as there are 6 rows starting with 1.
How can this situation be efficiently programmed? The length of each row is the same in the data and I have a very large size of the zero-one matrix.
Alternatives
(|
) andRepeated[]
e.g.Count[{{1, 1, 1, 1}, {1, 1, 0, 1}, {1, 0, 0, 1}, {0, 1, 0, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {1, 1, 1, 1}, {0, 1, 0, 0}}, {1, Repeated[0 | 1, {2}], 1}]
$\endgroup$