Skip to main content
deleted 6 characters in body
Source Link
corey979
  • 24.3k
  • 7
  • 60
  • 105
<< Developer`
f[a_List, threshold_] := {First@a}~Join~
  PartitionMap[If[#[[2]]Developer`PartitionMap[
   If[#[[2]] > #[[1]]*threshold, Mean@Drop[#, {2}], #[[2]]] &, a, 3, 1]
~Join~1]~Join~{Last@a}

f[a, 2]

{1, 1.2, 1.4, 1.1, 0.9, 0.9, 0.9, 1.1}

Employs the criterion $If[a_i>ba_{i-1},....]$, where threshold is the $b$.

<< Developer`
f[a_List, threshold_] := {First@a}~Join~
  PartitionMap[If[#[[2]] > #[[1]]*threshold, Mean@Drop[#, {2}], #[[2]]] &, a, 3, 1]
~Join~{Last@a}

f[a, 2]

{1, 1.2, 1.4, 1.1, 0.9, 0.9, 0.9, 1.1}

Employs the criterion $If[a_i>ba_{i-1},....]$, where threshold is the $b$.

f[a_List, threshold_] := {First@a}~Join~
  Developer`PartitionMap[
   If[#[[2]] > #[[1]]*threshold, Mean@Drop[#, {2}], #[[2]]] &, a, 3, 1]~Join~{Last@a}

f[a, 2]

{1, 1.2, 1.4, 1.1, 0.9, 0.9, 0.9, 1.1}

Employs the criterion $If[a_i>ba_{i-1},....]$, where threshold is the $b$.

added 87 characters in body
Source Link
corey979
  • 24.3k
  • 7
  • 60
  • 105
<< Developer`
f[a_List, threshold_] := {First@a}~Join~
  PartitionMap[If[#[[2]] > threshold#[[1]]*threshold, Mean@Drop[#, {2}], #[[2]]] &, a, 3, 1]
~Join~{Last@a}

f[a, 2]

{1, 1.2, 1.4, 1.1, 0.9, 0.9, 0.9, 1.1}

One can of course make it as general as one wishes, including into the arguments of f the length ofEmploys the partitionscriterion (3 here)$If[a_i>ba_{i-1},....]$, offsetwhere (1threshold here),is the conditions in If, what parts should be taken into account (the Drop part) etc. Above is an answer for this particular question to keep it simple$b$.

<< Developer`
f[a_List, threshold_] := {First@a}~Join~
  PartitionMap[If[#[[2]] > threshold, Mean@Drop[#, {2}], #[[2]]] &, a, 3, 1]
~Join~{Last@a}

f[a, 2]

{1, 1.2, 1.4, 1.1, 0.9, 0.9, 0.9, 1.1}

One can of course make it as general as one wishes, including into the arguments of f the length of the partitions (3 here), offset (1 here), the conditions in If, what parts should be taken into account (the Drop part) etc. Above is an answer for this particular question to keep it simple.

<< Developer`
f[a_List, threshold_] := {First@a}~Join~
  PartitionMap[If[#[[2]] > #[[1]]*threshold, Mean@Drop[#, {2}], #[[2]]] &, a, 3, 1]
~Join~{Last@a}

f[a, 2]

{1, 1.2, 1.4, 1.1, 0.9, 0.9, 0.9, 1.1}

Employs the criterion $If[a_i>ba_{i-1},....]$, where threshold is the $b$.

added 305 characters in body
Source Link
corey979
  • 24.3k
  • 7
  • 60
  • 105
<< Developer`
f[a_List, threshold_] := {First@a}~Join~
  PartitionMap[If[#[[2]] > threshold, Mean@Drop[#, {2}], #[[2]]] &, a, 3, 1]
~Join~{Last@a}

f[a, 2]

{1, 1.2, 1.4, 1.1, 0.9, 0.9, 0.9, 1.1}

One can of course make it as general as one wishes, including into the arguments of f the length of the partitions (3 here), offset (1 here), the conditions in If, what parts should be taken into account (the Drop part) etc. Above is an answer for this particular question to keep it simple.

<< Developer`
f[a_List, threshold_] := {First@a}~Join~
  PartitionMap[If[#[[2]] > threshold, Mean@Drop[#, {2}], #[[2]]] &, a, 3, 1]
~Join~{Last@a}

f[a, 2]

{1, 1.2, 1.4, 1.1, 0.9, 0.9, 0.9, 1.1}

<< Developer`
f[a_List, threshold_] := {First@a}~Join~
  PartitionMap[If[#[[2]] > threshold, Mean@Drop[#, {2}], #[[2]]] &, a, 3, 1]
~Join~{Last@a}

f[a, 2]

{1, 1.2, 1.4, 1.1, 0.9, 0.9, 0.9, 1.1}

One can of course make it as general as one wishes, including into the arguments of f the length of the partitions (3 here), offset (1 here), the conditions in If, what parts should be taken into account (the Drop part) etc. Above is an answer for this particular question to keep it simple.

Source Link
corey979
  • 24.3k
  • 7
  • 60
  • 105
Loading