1

I've got a multidimensional array that has 1 million sets of 3 points, each point being a coordinate specified by x and y. Calling this array pointVec, what I mean is

np.shape(pointVec) = (1000000,3,2)

I want to find the center of each of the set of 3 points. One obvious way is to iterate through all 1 million sets, finding the center of each set at each iteration. However, I have heard that vectorization is a strong-suit of Numpy's, so I'm trying to adapt it to this problem. Since this problem fits so intuitively with iteration, I don't have a grasp of how one might do it with vectorization, or if using vectorization would even be useful.

1
  • 3
    pointVec.mean(axis=1)? Commented Sep 28, 2020 at 18:06

1 Answer 1

1

It depends how you define a center of a three-point. However, if it is average coordinates, like @Quang mentioned in the comments, you can take the average along a specific axis in numpy:

pointVec.mean(1)

This will take the mean along axis=1 (which is second axis with 3 points) and return a (1000000,2) shaped array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.