[closed] 3.22 - orientation 2

1
1

I didn't get why

N = 1000
p = []
for i in range(N):
    x = robot()
    x.set_noise(0.05, 0.05, 5.0)
    p.append(x)

Isn't part of the 'setup' section of the code. If this is run twice, doesn't it reset te values of 'p'? I thought you should run the code once (finish with an array of 'p'), and then run it again using the previous 'p' as a starting point.

asked 06 Mar '12, 23:21

Gian%20Carlo%20Martinelli's gravatar image

Gian Carlo M...
1.5k21948
accept rate: 30%

closed 10 Mar '12, 20:10

Also, I tried creating a function that starts like this:

def run_filter():
p2 = []
for i in range(N):
p2.append(p[i].move(0.1, 5.0))
p = p2

I get an error: UnboundLocalError: local variable 'p' referenced before assignment

This didn't make any sense to me. Isn't 'p' a global variable?

(06 Mar '12, 23:24) Gian Carlo M... Gian%20Carlo%20Martinelli's gravatar image

The question has been closed for the following reason "The question is answered, right answer was accepted" by Gian Carlo Martinelli 10 Mar '12, 20:10


3 Answers:

I was just watching the answer video to this quiz, and he specifically doesn't include this stuff in the loop. "This is all initialization over here so you shouldn't touch it..." as he circled his pen over that code. The move and sense function calls were moved below the initializations so they could be rerun along with finding p2, w and p3.

link

answered 10 Mar '12, 00:07

Sandy%20Cannady's gravatar image

Sandy Cannady
1034

absolutelly right.... i feel stupid right now

(10 Mar '12, 20:10) Gian Carlo M... Gian%20Carlo%20Martinelli's gravatar image

Don't feel stupid. I coded it wrong, including the initialization in the loop :p We all make mistakes. The only stupid mistake is one you don't learn from.

(10 Mar '12, 21:16) Sandy Cannady Sandy%20Cannady's gravatar image

Same question here! Anyone?
Additionally I would like to confirm: to I understand correctly that in current interpretation the robot does its first move, senses, does particle stuff and then for the next time step the robot does not move, but instead stops. The second loop can be interpreted as the sensing and particle loop that is done after the robot stopped moving?

link

answered 09 Mar '12, 08:01

Roland%20Pihlakas's gravatar image

Roland Pihlakas
2425

bump? anyone?

link

answered 09 Mar '12, 19:59

Gian%20Carlo%20Martinelli's gravatar image

Gian Carlo M...
1.5k21948

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×5,185
×45
×12

Asked: 06 Mar '12, 23:21

Seen: 169 times

Last updated: 10 Mar '12, 21:16