Count from MatrixForm in mathematica

  • Mathematica
  • Thread starter 76Ahmad
  • Start date
  • #1
48
0

Main Question or Discussion Point

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
 

Answers and Replies

  • #2
1,069
29


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
48
0


thanks its work 100%
 

Related Threads for: Count from MatrixForm in mathematica

Replies
0
Views
2K
  • Last Post
Replies
1
Views
1K
Replies
3
Views
2K
Replies
3
Views
6K
Replies
2
Views
8K
Replies
2
Views
7K
Top