Last active
May 17, 2023 06:21
-
-
Save Dminor7/4cb2e0bd69db8ce7d6d9b38a5463b426 to your computer and use it in GitHub Desktop.
Calculate Average of vectors in Presto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
customer_id, | |
reduce( | |
event_vectors, | |
repeat(0.0, 512), -- dimension of vector here it is 512 | |
(sum_array, element_array) -> zip_with(sum_array, element_array, (s, e) -> s + e), | |
state_array -> transform(state_array, s -> s / cardinality(event_vectors)) | |
) as mean_event_vector | |
FROM( | |
SELECT | |
customer_id, | |
ARRAY_AGG( | |
event_vector | |
) AS event_vectors | |
FROM customer_behaviour_features | |
WHERE date BETWEEN '{start_date}' AND '{end_date}' | |
GROUP BY customer_id | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment