Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Count from MatrixForm in mathematica

  1. Sep 25, 2012 #1
    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
     
  2. jcsd
  3. Sep 25, 2012 #2
    Re: Count from "MatrixForm" in mathematica!!

    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.
     
  4. Sep 25, 2012 #3
    Re: Count from "MatrixForm" in mathematica!!

    thanks its work 100%
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Count from MatrixForm in mathematica
  1. Mathematica count (Replies: 1)

Loading...