/
githubmirror
/
photoprism
Обзор
Документация
Войти
/
githubmirror
/
photoprism
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
pkg/vector/centroid.go
40 строк
691 B
Michael Mayer
Vector: Reorganize package into topic-based files #4669
30 май 2026, 12:44
30 май 2026, 12:44
03129c9
Код
Авторство
О чём код?
package vector // Centroid returns the element-wise mean (centroid) of the given vectors as a // new, independent vector. Vectors whose length differs from the first vector // are ignored, and the mean is taken over the vectors actually included. It // returns nil when vs is empty or the first vector has no elements. func Centroid(vs Vectors) Vector { if len(vs) == 0 { return nil } dim := len(vs[0]) if dim == 0 { return nil } result := make(Vector, dim) n := 0 for _, v := range vs { if len(v) != dim { continue } for j := range dim { result[j] += v[j] } n++ } inv := 1 / float64(n) for j := range result { result[j] *= inv } return result }