Easiest way to split 2d numpy array in to two 1d arrays?

Viewed 2646

how do I get arrays x and y from array a?

a is a 2d array and I need to get x and y which are the columns of a

a=[[ 0  1]
  [ 2  3]
  [ 4  5]
  [ 6  7]
  [ 8  9]
  [10 11]]

x =[[0]   
    [2]
    [4]
    [6]
    [8]  
    [10]]

y =  [[1]
     [3]
     [4]
     [7]
     [9]
     [11]]
2 Answers

your array:-

arr=np.array([[0,1],[2,3],[4,5],[6,7],[8,9],[10,11]])

your answer:-

arr1,arr2=np.split(arr,2,axis=1)

Try this

numpy.split(array, 2, axis=1)
Related