Question: Receiving an error saying : Traceback (most recent call last): File /Users/liasmith/Desktop/Chegg code.py, line 25, in nw = np.dot(weights + dhs / (x + 0.0000001))

Receiving an error saying :

Traceback (most recent call last): File "/Users/liasmith/Desktop/Chegg code.py", line 25, in nw = np.dot(weights + dhs / (x + 0.0000001)) ValueError: operands could not be broadcast together with shapes (3,) (2,)

This code is supposed to construct a neural network with 4 inputs and one set of 3 hidden nodes using backpropagation in Python.

import numpy as np

x1,x2 = input("Enter two values: ").split()

w1,w2,w3,w4,w5,w6 = input("Enter six values: ").split()

k1,k2,k3 = input("Enter three values: ").split()

x = np.array([int(x1), int(x2)], dtype=float) weights = np.array([float(w1), float(w2), float(w3), float(w4), float(w5), float(w6)], dtype=float).reshape(2, 3) k = np.array([float(k1), float(k2), float(k3)], dtype=float)

m = np.dot(x, weights) p = 1 / (1 + np.exp(-m)) sm = np.dot(p, k) y = 1 / (1 + np.exp(-sm))

print("y = ", y)

res = 0 - y q1 = res * (np.exp(-sm)) / ((1 + np.exp(-sm))**2) dw = q1 * p / (p + 0.0000001) nk = k + dw dhs = q1 * (1 + np.exp(-np.abs(m)))**2 / k * np.exp(-np.abs(m)) nw = (weights + dhs / (x + 0.0000001)

k = nk weights = nw

m = np.dot(x, weights) p = 1 / (1 + np.exp(-m)) sm = np.dot(p, k) y = 1 / (1 + np.exp(-sm))

print("y = ", y)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!