Returns the arithmetic mean of the values in the given iterable or iterator.
(iterable, length=None)
| 1391 | # The k_means() and hierarchical() functions work with Vector objects or dictionaries. |
| 1392 | |
| 1393 | def mean(iterable, length=None): |
| 1394 | """ Returns the arithmetic mean of the values in the given iterable or iterator. |
| 1395 | """ |
| 1396 | if length is None: |
| 1397 | if not hasattr(iterable, "__len__"): |
| 1398 | iterable = list(iterable) |
| 1399 | length = len(iterable) |
| 1400 | return sum(iterable) / float(length or 1) |
| 1401 | |
| 1402 | def centroid(vectors=[], features=[]): |
| 1403 | """ Returns the center of the given list of vectors. |