From ab98173e7f6568851e527e511bc8b9901a96a120 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Oct 2025 12:48:59 +0000 Subject: [PATCH] Fix ValueError in main Perceptron.ipynb for NumPy 2.x compatibility Co-authored-by: leestott <2511341+leestott@users.noreply.github.com> --- lessons/3-NeuralNetworks/03-Perceptron/Perceptron.ipynb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lessons/3-NeuralNetworks/03-Perceptron/Perceptron.ipynb b/lessons/3-NeuralNetworks/03-Perceptron/Perceptron.ipynb index e74eb6ba..54ad4e59 100644 --- a/lessons/3-NeuralNetworks/03-Perceptron/Perceptron.ipynb +++ b/lessons/3-NeuralNetworks/03-Perceptron/Perceptron.ipynb @@ -462,10 +462,9 @@ " neg_out = np.dot(negative_examples, weights) \n", " pos_correct = (pos_out >= 0).sum() / float(pos_count)\n", " neg_correct = (neg_out < 0).sum() / float(neg_count)\n", - " # make correction a list so it is homogeneous to weights list then numpy array accepts\n", - " snapshots.append((np.concatenate(weights),[(pos_correct+neg_correct)/2.0,0,0]))\n", + " snapshots.append([np.copy(weights).flatten(), (pos_correct+neg_correct)/2.0])\n", "\n", - " return np.array(snapshots)\n", + " return np.array(snapshots, dtype=object)\n", "\n", "snapshots = train_graph(pos_examples,neg_examples)\n", "\n", @@ -477,7 +476,7 @@ " pylab.plot(np.arange(len(snapshots[:,1])), snapshots[:,1])\n", " pylab.ylabel('Accuracy')\n", " pylab.xlabel('Iteration')\n", - " pylab.plot(step, snapshots[step,1][0], \"bo\")\n", + " pylab.plot(step, snapshots[step,1], \"bo\")\n", " pylab.show()\n", "def pl1(step): plotit(pos_examples,neg_examples,snapshots,step)" ] @@ -1078,4 +1077,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file