-2

I am new in this website so sorry if I am not doing this thing right but I have a problem.What should i do to fix this ?

import numpy as np
X = (([0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]))    
h = (([0, 0], [0, 1], [1, 0], [1, 1]))
class NeuralNetworks(object):
    def __init__(self):
        self.InputSize = 4
        self.OutputSize = 2
        self.HiddenSize = 3

        self.w1 = np.random.randn(self.InputSize, self.HiddenSize)
        self.w2 = np.random.randn(self.HiddenSize, self.OutputSize)

    def forward(self, x):
        self.z = np.dot(x, self.w1) 
        self.z2 = self.sigmoid(self.z) 
        self.z3 = np.dot(self.z2, self.w2) 
        output = self.sigmoid(self.z3)
        return output

    def sigmoid(self, k ):
        return 1/(1 + np.exp(-k))
    def delta (self,k):
        return k*(1-k)
    def back(self, x, h, output):
       self.error = h-output 
       self.outputdelta = self.error *self.delta(output)
       self.z2error=self.outputdelta.dot(self.w2.T)
       self.z2delta = self.z2error * self.delta(self.z2)
       self.w1 += x.T.dot(self.z2delta)
       self.w2 += self.z2.T.dot(self.outputdelta)    

AttributeError: 'tuple' object has no attribute 'T'

hacquerqop
  • 7
  • 1
  • 4

1 Answers1

2

I assume your inputs should be NumPy arrays. You are passing tuples (indicated by the parentheses ()). It might be enough to do this:

import numpy as np

X = np.array(([0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]))    
y = np.array(([0, 0], [0, 1], [1, 0], [1, 1]))
Dion
  • 1,492
  • 11
  • 14