1 Replies - 1521 Views - Last Post: 10 March 2011 - 05:20 PM Rate Topic: -----

#1 hogbipeking  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-January 11

how do you convert an list to an indexing array?

Posted 10 March 2011 - 04:29 PM

Hello:
I am a begineer python programmer... just completed a introduction course.
I am doing some programming on my own... when I came ran into this problem.
I keep on getting this error "IndexError: too many indices." This is becouse the "x" is a indexing array and the t is a list. How do i convert this list to an indexing array?
thank you for your help in advance.
from pylab import *
from numpy import *

y=[1,2,3,4,5,6,7,8,9,10]

x = ones((1,4))*linspace(0,4,4)
t=y[0:4]  #pick out four numbers

x = transpose(x)
t = transpose(t)
print " len t= : ",len(t)
print " len x= : ",len(x)
print "t = : ",t
print "x = : ",x
# Split into training, testing, and validation sets
train = x[0::2,:]
test = x[1::4,:]
valid = x[3::4,:]
traintarget = t[0::2,:]   #I get an error here
testtarget = t[1::4,:]
validtarget = t[3::4,:]

# Plot the data
plot(x,t,'o')
xlabel('x')
ylabel('t')
show()



Is This A Good Question/Topic? 0
  • +

Replies To: how do you convert an list to an indexing array?

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: how do you convert an list to an indexing array?

Posted 10 March 2011 - 05:20 PM

What are you trying to accomplish with this code? I think a better solution would be to modify your approach a bit.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1