python - Create 2 dimensional array with 2 one dimensional array -


i used numpy , scipy , there function care dimension of array have function name covexhull(point) accept point 2 dimensional array.

hull = convexhull(points)

in [1]: points.ndim out[1]: 2 in [2]: points.shape out[2]: (10, 2) in [3]: points out[3]:  array([[ 0. ,  0. ],        [ 1. ,  0.8],        [ 0.9,  0.8],        [ 0.9,  0.7],        [ 0.9,  0.6],        [ 0.8,  0.5],        [ 0.8,  0.5],        [ 0.7,  0.5],        [ 0.1,  0. ],        [ 0. ,  0. ]]) 

as can see above points numpy ndim 2.

now have 2 different numpy array (tp , fp) (for example fp)

in [4]: fp.ndim out[4]: 1 in [5]: fp.shape out[5]: (10,) in [6]: fp out[6]:  array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.4,         0.5, 0.6,  0.9,  1. ]) 

my question how can create 2 dimensional numpy array points tp , fp

if wish combine 2 10 element 1-d arrays 2-d array np.vstack((tp, fp)).t it. np.vstack((tp, fp)) return array of shape (2, 10), , t attribute returns transposed array shape (10, 2) (i.e. 2 1-d arrays forming columns rather rows).

>>> tp = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> tp.ndim 1 >>> tp.shape (10,)  >>> fp = np.array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) >>> fp.ndim 1 >>> fp.shape (10,)  >>> combined = np.vstack((tp, fp)).t >>> combined array([[ 0, 10],        [ 1, 11],        [ 2, 12],        [ 3, 13],        [ 4, 14],        [ 5, 15],        [ 6, 16],        [ 7, 17],        [ 8, 18],        [ 9, 19]])  >>> combined.ndim 2 >>> combined.shape (10, 2) 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -