Closed AnilSarode closed 11 months ago
Hi @AnilSarode ,
Thank you for reporting this.
I ran it in Google Colab and it works but it produces a deprecation warning (Colab uses Matplotlib 3.7.1 right now), so I am assuming you're using a more recent version of Matplotlib, is it the case?
Nonetheless, I fixed the code accordingly, so it does not produce the deprecation warning anymore, so I hope it solves your issue. Please let me know if it works well, and if you find any other errors.
Thank you for your support :-)
Best, Daniel
Hi@dvgodoy Thanks a lot for the quick response. Yes, the issue is resolved. I am running the code on my local machine, and using Matplotlib 3.5.1. Could you please explain what exactly you did in the code cause I was trying to figure out and does the error is related to this https://stackoverflow.com/questions/4674473/valueerror-setting-an-array-element-with-a-sequence
Hi @AnilSarode
I'm glad to hear it's working for you now :-)
OK, it seems the warning came from Numpy then, I was re-reading your error message, and the exception is raised from Numpy.
In the code of the original figure3()
function in plots/chapter0.py
, I was mixing 1-D Numpy arrays (b and w) and individual float values (w0 and x0), so it was complaining:
ax.plot([x0, x0], [b + w * x0, y0 - .03], c='r', linewidth=2, linestyle='--')
...
ax.arrow(x0, b + w * x0 + .05, 0, -.03, color='r', shape='full', lw=0, length_includes_head=True, head_width=.03)
The only change I made was to retrieve the values from inside the Numpy arrays by adding [0]
to them. They had only a single value, so the end result is the same, and the warning is gone because I am not mixing anything:
ax.plot([x0, x0], [b[0] + w[0] * x0, y0 - .03], c='r', linewidth=2, linestyle='--')
...
ax.arrow(x0, b[0] + w[0] * x0 + .05, 0, -.03, color='r', shape='full', lw=0, length_includes_head=True, head_width=.03)
It's not a problem of types (as suggested by the StackOverflow link) but a problem of mixing elements with different dimensions. I guess Numpy is getting more strict when it comes to those operations.
Hello, I am getting the error in following code
figure3(x_train, y_train, b, w)
error is