-1

I would like to calculate number of elements in a matrix that are equal to Zero or One. The goal is calculate density of elements in a matrix that are equal to zero or one. I use this to calculate sparseness of the matrix as well.

Generally in Sparse matrix, majority of the elements are ZEROs. But in the matrix I privided has very few Zero and Ones and elements having value 'X' are more in number. Hence I would like to find count of elements having zero and one first. Then I shall use them to calculate Sparseness and Sparse density of the matrix.

The matrix looks like:

\begin{matrix} 1 & 0 & x & x & x & x & 0 & x & x & x & 0 & x & x & x & x & x & x & x\\ x & x & x & x & 0 & x & x & x & x & x & x & x & x & x & 1 & x & x & 0\\ 0 & x & x & x & x & 1 & x & x & x & x & x & 0 & x & x & x & x & x & x\\ \end{matrix}

svp
  • 1
  • 2
    This is, quite literally, impossible to answer without you giving us the matrix in question. Please provide additional context in your question describing your problem. In particular, where the problem comes from, your understanding of it, your attempts at it, etc. – PrincessEev Dec 28 '18 at 12:22
  • The given matrix is N X M matrix which has Zero, one and 'X' as an elements. Usually this matrix will have very less Zeros and Ones but more 'X'. Here 'X' is not variable and it could be fixed number. – svp Dec 28 '18 at 12:25
  • The given matrix is N X M matrix which has Zero, one and 'X' as an elements. Usually this matrix will have very less Zeros and Ones but more 'X'. Here 'X' is not variable and it could be fixed number. The matrix looks like: $$ \begin{matrix} 1 & 0 & x & x & x & x & 0\ x & x & x & x & 0 & x & x\ 0 & x & x & x & x & 1 & x\ \end{matrix} $$ – svp Dec 28 '18 at 12:32
  • More facts are needed. Can you post the entire question? – For the love of maths Dec 28 '18 at 12:33
  • I have following matrix, which is used in digital electronics. This matrix will have elements as '0', '1' and 'X'. Here 'X' is not variable, it could be unknown value which electronic device assigns. Usually this matrix will have very less '0's and '1's but more 'X'. I would like to find number of '0's and '1' present in the matrix. The matrix looks like: $$ \begin{matrix} 1 & 0 & x & x & x & x & 0\ x & x & x & x & 0 & x & x\ 0 & x & x & x & x & 1 & x\ \end{matrix} $$ – svp Dec 28 '18 at 12:36
  • Note: it is more convenient if you edit your question directly instead of posting it in a comment. If I understand correctly you are looking for a function $f$ such that for any matrix $A$, $f(A)$ is the number of zeros. Is this correct? – Michh Dec 28 '18 at 20:57

1 Answers1

0

If I understand the question correctly, the goal is to count the number of elements in a matrix that are equal to zero or one. There are a few ways to answer this.

For arbitrary matrices, the only way is to inspect each element and count manually. Zero and one are not special values in matrices, so there aren't special operations to extract a count. In fact, since it was mentioned that the matrix values come from electronics, the values of the matrix elements will not in general be integers. So, the check for zero and one would look more like $|x| < \epsilon$ for zero and $|x-1| < \epsilon$ for one with $\epsilon$ being some small constant. This is to handle floating point uncertainties in software.

Now, if the matrix has more structure, then some cleverness can be brought to bear. For example, if every element an $n \times m$-matrix $M$ is either zero or one, then the count of ones in the matrix is given by $$c_1 = \textrm{tr}(M^TM),$$ and the count of zeros is given by $$c_0 = nm - c_1,$$ where $\textrm{tr}(M)$ is the trace of $M$ and $M^T$ is the transpose of $M.$

This can be seen by noting that the diagonal elements of $M^TM$ are the dot products of the column vectors of $M$ with themselves. Also, the dot product of a binary (consisting of zeros and ones) vector with itself is equal to the number of ones in that vector.

Mark H
  • 1,283
  • Thanks a lot Mr Mark H, for providing answer. My motto is to calculate Density and sparseness of the matrix based on the count of elements equal tp zero or one. The count of elements equal to zero and one decided the sparseness of the matrix. Less number of elements equal to Zero and one, more the sparseness. – svp Dec 29 '18 at 07:58