Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11678
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Count inside a matrix? |
| Date | 2012-09-09 09:11 +0000 |
| Message-ID | <k2hmgj$ptk$1@smc.vnet.net> (permalink) |
| References | <20120908070948.80D4C685C@smc.vnet.net> |
| Organization | Time-Warner Telecom |
matrix = Table[RandomInteger[{0, 10}], {5}, {3}]
{{3, 5, 7}, {5, 2, 9}, {7, 3, 7}, {6, 4, 1}, {2, 5, 8}}
Use levelspec argument to Count
Count[matrix, 5, 2]
3
Count[matrix, _?(# > 5 &), 2]
6
Or flatten matrix before using Count
Count[Flatten[matrix], 5]
3
Count[Flatten[matrix], _?(# > 5 &)]
6
Bob Hanlon
On Sat, Sep 8, 2012 at 3:09 AM, Sergio Sergio <zerge69@gmail.com> wrote:
> Hi, does anybody know how to count elements within a matrix?
> I know how that Count works for lists, but it does not seem to work for a matrix.
> Any tips?
>
> Thanks
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Count inside a matrix? Bob Hanlon <hanlonr357@gmail.com> - 2012-09-09 09:11 +0000
csiph-web