# how do you convert an list to an indexing array?

Page 1 of 1

## 1 Replies - 1609 Views - Last Post: 10 March 2011 - 05:20 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=221376&amp;s=5b0f47b97d55fdff0690f6463a8f7420&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hogbipeking

Reputation: 0
• 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?
```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

• Pythoneer

Reputation: 813
• Posts: 2,192
• 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.