Count from MatrixForm in mathematica

  • Context: Mathematica 
  • Thread starter Thread starter 76Ahmad
  • Start date Start date
  • Tags Tags
    Count Mathematica
Click For Summary
SUMMARY

The discussion focuses on counting zero elements in a matrix using Mathematica. Users are advised to avoid using the "MatrixForm" wrapper for processing, as it converts the matrix into a display format that is not suitable for calculations. Instead, the correct approach involves using the "Count" function on a flattened version of the matrix before applying "MatrixForm". The example provided demonstrates that counting zeros directly from the matrix yields accurate results, while counting from "MatrixForm" returns zero.

PREREQUISITES
  • Understanding of Mathematica syntax and functions
  • Familiarity with matrix operations in Mathematica
  • Knowledge of the "Count" function in Mathematica
  • Basic concepts of data flattening in programming
NEXT STEPS
  • Explore the "Count" function in Mathematica for various data types
  • Learn about matrix manipulation techniques in Mathematica
  • Research the implications of using display wrappers like "MatrixForm"
  • Investigate the "Flatten" function in Mathematica for multi-dimensional arrays
USEFUL FOR

Mathematica users, data analysts, and anyone working with matrix computations who need to efficiently count elements within matrices.

76Ahmad
Messages
46
Reaction score
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


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.
 


thanks its work 100%
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 18 ·
Replies
18
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K