rlvaugh / Real_World_Python

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

Update bayes.py #2

Open PreacherBaby opened 3 years ago

PreacherBaby commented 3 years ago

LINE #234 - fixed "TypeError: only integer scalar arrays can be converted to a scalar index" in line #234 which caused the program to crash and preventing it from drawing the circle when the sailor coordinates are retrieved.

rlvaugh commented 3 years ago

Thank you. I'm not sure why this is happening as I can't reproduce it in the original setup. What happens if you use sailor_x[0] rather than sailor_x.item(0)?

PreacherBaby commented 3 years ago

Good morning/afternoon/evening, Excuse me for the late reply.

I've just checked sailor_x[0] - it works fine as item(0) variant in this case!

rlvaugh commented 3 years ago

Great! I need the shortest syntax possible so we don't get a line wrap in the book when it's updated in the next printing. Thanks a lot.

PreacherBaby commented 3 years ago

Your book is really cool! It is hard sometimes. But it's cool1

Thank you, too. Have a nice day!

rlvaugh commented 3 years ago

Thanks. If you have any questions you can reach me through Linkedin.com.

AxZxP commented 3 years ago

If anyone reads this and wonder what happens :

rng.choice(array, size=None)

returns a single value if the array is flat and a single array of n dimension if the array has n dimensions (with n > 1). But

rng.choice(array, size=1)

returns an array even if the shape of the array is 1.

So the best option with rng.choice() is in my opinion to always leave size=None (which is the default value) whenever we want to pick only one value. For this exemple, it would simplify the awkward indexing in the following circle fonction.

rlvaugh commented 3 years ago

Please see the recent update to the bayes.py code (lines 90, 91, and 234). This will hopefully clear up the problems some users have with drawing the circle.