Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.8K Views
|
7 Replies
|
7 Total Likes
View groups...
Share
Share this post:

[?] Count the total presence of this group in a sequence?

POSTED BY: Mutatis Mutandis
7 Replies
Posted 8 years ago

In this case, using Table[] and Sum[] instead of Map[] makes for less confusing code:

Table[Sum[SequenceCount[s, {g}], {g, group}], {s, subseq}]

Alternatively, you can use a single Table[] and apply Total[] afterwards:

Total[Table[SequenceCount[s, {g}], {s, subseq}, {g, group}], {2}]
POSTED BY: J. M.

When nesting pure function you had better give distinctive names to the variables, to avoid conflict. For example

group = {05, 60, 13, 58, 47};
countInSequence[mySequence_] := 
  Total[Function[element, SequenceCount[mySequence, {element}]] /@ 
    group];
Map[countInSequence, subseq]
POSTED BY: Gianluca Gorni
Posted 8 years ago

Alternatively: Table[Length[Intersection[s, g]], {g, newgroup}, {s, newseq}]; no need to use Part[].

POSTED BY: J. M.
Posted 8 years ago

Does this answer your last question ok?

Table[Length[Intersection[newseq[[q]], newgroup[[i]]]], {i, 1, 
  Length[newgroup]}, {q, 1, Length[newseq]}]
POSTED BY: Paul Cleary

WORK!

POSTED BY: Mutatis Mutandis
POSTED BY: Mutatis Mutandis

TNK'S 4 YOUR BEST SOLUTION "sei sempre er mejo"

POSTED BY: Mutatis Mutandis
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard