Content deleted Content added
m →Computer programming: change to https if the server sends HSTS header, replaced: http://www.python.org → https://www.python.org using AWB |
simplify |
||
(12 intermediate revisions by 9 users not shown) | |||
Line 1:
{{Short description|Concepts in statistics and computer science}}
An '''Aggregate pattern''' can refer to concepts in either statistics or computer programming. Both uses deal with considering a large case as composed of smaller, simpler, pieces.▼
{{one source |date=March 2024}}
▲An '''Aggregate pattern''' can refer to concepts in either statistics or computer programming. Both uses
== Statistics ==
An aggregate pattern is an important statistical concept in many fields that rely on [[statistics]] to predict the behavior of large groups, based on the tendencies of subgroups to consistently behave in a certain way. It is particularly useful in [[sociology]], [[economics]], [[psychology]], and [[criminology]].
== Computer programming ==
In ''[[Design Patterns]]'', an aggregate is not a [[Software design pattern|design pattern]] but rather refers to an object such as a list, vector, or generator which provides an interface for creating [[iterator]]s. The following example code is in [[Python (programming language)|Python]].
<
def fibonacci(n: int):▼
while count < n:▼
a, b = b, a + b
▲def fibonacci(n):
▲ count = 0
▲ while count < n:
▲ count += 1
▲ a,b = b, a+b
for x in fibonacci(10):
def fibsum(n: int) -> int:
total = 0
for x in fibonacci(n):
total += x
return total
def fibsum_alt(n: int) -> int:
"""
Alternate implementation. demonstration that Python's built-in function sum()
works with arbitrary iterators.
"""
return sum(fibonacci(n))
myNumbers = [1, 7, 4, 3, 22]
def average(g) -> float:
return float(sum(g)) / len(g) #
</syntaxhighlight>
Python hides essentially all of the details using the [https://
== See also ==
Line 55 ⟶ 51:
{{Reflist}}
[[Category:Software design patterns]]
[[Category:Articles with example Python (programming language) code]]
|