0

I have a set of data which is in columns, where the first column is the x values. How do i read this in?

pythonman11
  • 1
  • 1
  • 5

1 Answers1

0

If you want to store both, x and y values you can do

ydat = np.zeros((data.shape[1]-1,data.shape[0],2))

# write the x data
ydat[:,:,0] = data[:,0]

# write the y data    
ydat[:,:,1] = data[:,1:].T

Edit: If you want to store only the y-data in the sub arrays you can simply do

ydat = data[:,1:].T

Working example:

t = np.array([[ 0.,  0.,  1.,  2.],
              [ 1.,  0.,  1.,  2.],
              [ 2.,  0.,  1.,  2.],
              [ 3.,  0.,  1.,  2.],
              [ 4.,  0.,  1.,  2.]])


a = t[:,1:].T

a
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 2.,  2.,  2.,  2.,  2.]])
plonser
  • 3,323
  • 2
  • 18
  • 22
  • I don't really understand what that code does but it doesn't seem to work for my code. Thank you though. Is there anyway to modify my original code to which it will put it into sub arrays? – pythonman11 Apr 29 '15 at 17:15
  • @pythonman11 : what does not work? Do you expect another shape of the output? – plonser Apr 29 '15 at 17:18
  • I expect an array with n sub arrays, where n is the number of y columns. So that i can then call separate columns at will for use from the array – pythonman11 Apr 29 '15 at 17:21
  • That's what my code is doing ... Do you get an error with my code or what is wrong? Does my example work? What would be the correct output of my working example? – plonser Apr 29 '15 at 17:25
  • Its putting them out into pairs, so when i try calling the 3rd value from the first sub array there is an error. – pythonman11 Apr 29 '15 at 17:32
  • If I call `a[0,3]` I get `array([ 3., 0.])`. It would really help if you could bring a small size matrix `data` and show the result you want to have ... otherwise I and possible others can not help you because it is not really clear what you are asking ... – plonser Apr 29 '15 at 17:37
  • I have edited the question to show the format of the data and how i would like the array. – pythonman11 Apr 29 '15 at 17:43
  • I apologise i have just read your edit and it was the xdata that was messing the arrays up. Thank you! – pythonman11 Apr 29 '15 at 18:05