Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert 1D String to multidimensional array - Numpy

I have theses points that I need to be in a 2,N array. I tried using Numpy but couldn't get it to work. Any help will do.

30.90,401.01;96.91,384.22;80.70,340.79;67.38,337.90;55.80,300.26;72.01,299.68;92.28,310.10;99.81,331.53;92.86,340.79;108.49,380.16;108.49,382.48;168.13,373.22;352.83,380.74;474.43,393.48;535.80,409.69;560.70,369.16;550.28,362.79;562.44,333.26;592.55,328.05;605.28,329.79;594.28,363.95;572.28,370.32;549.12,413.17;714.14,469.33;716.45,479.17;203.45,479.75;0.00,479.17;0.22,365.11 
like image 741
Shaggy Avatar asked Sep 18 '26 04:09

Shaggy


1 Answers

You can use matrix:

s = '30.90,401.01;96.91,384.22;80.70,340.79'
np.array(np.matrix(s))

Output:

array([[ 30.9 , 401.01],
       [ 96.91, 384.22],
       [ 80.7 , 340.79]])
like image 179
Quang Hoang Avatar answered Sep 19 '26 19:09

Quang Hoang