Count from MatrixForm in mathematica

  • Mathematica
  • Thread starter 76Ahmad
  • Start date
  • #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
 

Answers and Replies

  • #2
Bill Simpson
1,073
32


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


thanks its work 100%
 

Suggested for: Count from MatrixForm in mathematica

  • Last Post
Replies
5
Views
489
  • Last Post
Replies
1
Views
643
Replies
1
Views
409
Replies
6
Views
779
Replies
0
Views
356
Replies
5
Views
844
Replies
1
Views
463
Replies
5
Views
300
Replies
1
Views
713
Replies
2
Views
479
Top