| 114 | |
| 115 | template <typename T> |
| 116 | std::vector<T> horizontal_avg(const std::vector<std::vector<T>>& data) { |
| 117 | size_t rows = data.size(); |
| 118 | size_t cols = data[0].size(); |
| 119 | |
| 120 | std::vector<T> avg(cols, 0); |
| 121 | for (auto& row : data) { |
| 122 | for (size_t j = 0; j < cols; ++j) { |
| 123 | avg[j] += row[j]; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | for (size_t j = 0; j < cols; ++j) { |
| 128 | avg[j] /= rows; |
| 129 | } |
| 130 | |
| 131 | return avg; |
| 132 | } |
| 133 | } // namespace rabitqlib |