rlvaugh / Real_World_Python

Code and supporting files for book Real World Python
169 stars 115 forks source link

Chapter_1\bayes.py #1

Open Royml opened 3 years ago

Royml commented 3 years ago

Chapter_1\bayes.py", line 234, in main cv.circle(app.img, (sailor_x, sailor_y), 3, (255, 0, 0), -1) TypeError: only integer scalar arrays can be converted to a scalar index

rlvaugh commented 3 years ago

Hi Royml, I'm unable to reproduce the error on Windows or macOS. Try turning the sailor coordinates into a tuple: cv.circle(app.img, ((sailor_x, sailor_y)), 3, (255, 0, 0), -1). If this doesn't help, try running the bayes.py code downloaded from github. This ran okay for me. Let me know how it goes.

Royml commented 3 years ago

Hi, the tupl(ing) didn't fix it, but I did manage to resolve with int() on the sailor_x and sailor_y.

It could be a python version issue, mine is 3.8.5

rlvaugh commented 3 years ago

Okay. I'm in the process of transferring to a new computer and installing Anaconda with the latest version of Python. I'll revisit this when I have everything up and running in the next week or so. Thanks.

rlvaugh commented 3 years ago

Could you also let me know which version of OpenCV you are using? Thanks.

rlvaugh commented 3 years ago

cv.circle(app.img, (sailor_x.item(0), sailor_y.item(0)), 3, (255, 0, 0), -1) # Returns a standard Python scalar and should fix the problem. Alternatively, using sailor_x[0] and sailor_y[0] should also work.

A better solution would be changing lines 90 & 91 to the following: self.sailor_actual[0] = np.random.choice(self.sa1.shape[1]) self.sailor_actual[1] = np.random.choice(self.sa1.shape[0])

This returns an integer directly so no need to jump through hoops. Thanks to Alexander Valarus for pointing this out.

dougler commented 3 years ago

getting the sailor position to show I could not get the last "else" line cv.circle...to work I had to modify the draw _map method with an extra parameter 'actual_position' which is set to(0,00 when the not wanted and to the position when wanted the draw_map method then includes the "cv. circle.." which is activated when actual_position !=(0,0)

I also had to destroyAlllWindows after the imshow to get the draw_map to work twice

rlvaugh commented 3 years ago

Hmmm. A few questions: -What OS are you using? -Are you launching the program from a terminal/powershell or from your IDE? -Are you running the bayes.py I supplied on github? This has been tested on multiple systems.

dougler commented 3 years ago

I ran your code again, it works fine. I’ll there must have been an erro between the chair and the key board Thanks again

Sent from my iPhone

On Jan 16, 2021, at 1:11 PM, rlvaugh notifications@github.com wrote:

 Hmmm. A few questions: -What OS are you using? -Are you launching the program from a terminal/powershell or from your IDE? -Are you running the bayes.py I supplied on github? This has been tested on multiple systems.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

rlvaugh commented 3 years ago

That's good news! It's easy to mistype something going from the book to the keyboard. If you run the supplied code and it works differently, you can compare your code to mine using online comparison tools or by pasting the code into two different Microsoft Word docs and then using the compare feature under the Review tab. This will highlight any changes, making them easy to find.

dougler commented 3 years ago

Thanks for the tip!

On Sat, Jan 16, 2021 at 5:13 PM rlvaugh notifications@github.com wrote:

That's good news! It's easy to mistype something going from the book to the keyboard. If you run the supplied code and it works differently, you can compare your code to mine using online comparison tools or by pasting the code into two different Microsoft Word docs and then using the compare feature under the Review tab. This will highlight any changes, making them easy to find.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rlvaugh/Real_World_Python/issues/1#issuecomment-761709681, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANARLRJDAYBWXPX34CQI3OLS2I2VLANCNFSM4VQ3I2CQ .

I’m still flummoxed by the gensim import Have asked pyCharm for their advice. I had just updated pyCharm when the imports started to have problems -- Regards, Doug Brown