# Table with weight 2/3
a = np.array(
[[0, 0],
[12, 12]]
)
# Table with weight 1/3
b = np.array(
[[12, 6],
[9, 3]]
)
# Returned table
c = np.array(
[[4, 2],
[11, 9]]
)
I have a, b (each holding some points) and I want to compute efficiently given their weights, matrix c holding the pairwise point averages. Something like their weighted centroid.
How can I do that? Thanks
CodePudding user response:
You can use simple basic numpy matrix operations:
c = a * weight_a b * weight_b
# With your example :
c = a * 2 / 3 b * 1 / 3
# array([[ 4., 2.],
# [11., 9.]])