Re: Count inside a matrix?
- To: mathgroup at smc.vnet.net
- Subject: [mg128015] Re: Count inside a matrix?
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Sun, 9 Sep 2012 05:08:46 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <20120908070948.80D4C685C@smc.vnet.net>
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 at 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 >
- References:
- Count inside a matrix?
- From: Sergio Sergio <zerge69@gmail.com>
- Count inside a matrix?