Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to compute efficiently in python, the weighted point average (centroid) for each pair of points across two arrays

# 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.]])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading