[SOLVED] Is there an efficient way of splitting a 2-D numpy array(an array of coordinates) to two 1-D numpy arrays?

Issue

Here is my array and I would like to separate it to two arrays, one contains all first values of pairs and one with all second values of pairs. Is there an efficient way to do that?

array([[-0.43042553, -0.1224234 ],
       [-2.03524537,  0.56015045],
       [ 1.40186973, -0.74534088],
       [-0.04612834, -0.43374017],
       [-0.71154051, -0.54219998],
       [-0.10434967, -0.80116922],
       [-0.28625899, -1.15067218],
       [ 2.18190517,  0.52953827]])

Solution

Similar to other answers but more concise:

a1, a2 = arr.T

Answered By – Julien

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *