# ----------# # In this exercise, you will add in code that decides whether a perceptron will fire based# on the threshold. # ----------import numpy as np
classPerceptron:"""
This class models an artificial neuron with step activation function.
"""def__init__(self, weights = np.array([1]), threshold = 0):"""
Initialize weights and threshold based on input arguments. Note that no
type-checking is being performed here for simplicity.
"""
self.weights = weights
self.threshold = threshold
defactivate(self,inputs):"""
Takes in @param inputs, a list of numbers equal to length of weights.
@return the output of a threshold perceptron with given inputs based on
perceptron weights and threshold.
"""# The strength with which the perceptron fires.
strength = np.dot(self.weights, inputs)
# TODO: return 0 or 1 based on the thresholdif strength <= self.threshold :
self.result =0# TODOelse:
self.result =1# TODO return self.result
def <