Count from MatrixForm in mathematica

In summary, to count the number of zeros in a matrix in Mathematica, you should use the Count function on the flattened version of the matrix, rather than on the MatrixForm version. MatrixForm should only be used for display purposes and not for further processing of the matrix.
  • #1
76Ahmad
48
0
Count from "MatrixForm" in mathematica!

Hi every one, I really need help on this task..

how do I Count only the zeros elements from a MatrixForm in MATHEMATICA

Suppose I have a Matrix 100X100 full with numbers and
I just need to know how many zero is there on this matrix

thanks
 
Physics news on Phys.org
  • #2


First, all the various "Form"s are wrappers that turn an ordinary simple Mathematica value into something for display and aren't usually for further processing.

So, if you have your matrix before you put it into MatrixForm then you can do this

In[1]:= m=Table[RandomInteger[{5},{5}]

Out[1]= {{1,0,1,1,1},{0,1,1,0,0},{1,0,0,1,0},{0,0,0,0,0},{1,0,1,1,0}}

In[2]:= Count[Flatten[m],0]

Out[2]= 14

and that has successfully counted the zeros in the matrix.

But

In[4]:= Count[MatrixForm[m],0]

Out[4]= 0

In[5]:= Count[Flatten[MatrixForm[m]],0]

Out[5]= 0

So if you want to see a pretty desktop published version of your matrix... use MatrixForm, but if you want to get any work done on your matrix then do not use MatrixForm.
 
  • #3


thanks its work 100%
 

What is the purpose of "Count from MatrixForm" in Mathematica?

The "Count from MatrixForm" function in Mathematica is used to count the number of elements in a matrix. It is particularly useful when dealing with large matrices and can help with organizing and analyzing data.

How do I use "Count from MatrixForm" in Mathematica?

To use "Count from MatrixForm" in Mathematica, you first need to input a matrix in the MatrixForm format. Then, you can use the Count function with the MatrixForm as the first argument and the desired element to be counted as the second argument. For example, Count[MatrixForm[{1,2,3,4,5}], 3] will return the number of times the element 3 appears in the matrix.

Can "Count from MatrixForm" be used with matrices of different dimensions?

Yes, "Count from MatrixForm" can be used with matrices of different dimensions. As long as the matrix is in the MatrixForm format, the function can count the elements regardless of the matrix's dimensions.

Are there any limitations to using "Count from MatrixForm" in Mathematica?

One limitation of using "Count from MatrixForm" is that it can only count elements that are explicitly present in the matrix. It cannot count elements that are generated through functions or formulas. Additionally, the function may not work properly if the matrix is not in the correct format.

Can "Count from MatrixForm" be used for non-numerical elements?

Yes, "Count from MatrixForm" can be used for non-numerical elements. It can count any type of element, including strings, symbols, and functions, as long as they are in the matrix in the MatrixForm format.

Similar threads

Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
415
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
236
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
892
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Back
Top