Tashkent university of information technologies named after muhammad al-khorezmi
Download 172.03 Kb.
|
import numpy as np
# Define the perceptron function def perceptron(inputs, weights, bias): # Calculate the weighted sum of inputs weighted_sum = np.dot(inputs, weights) + bias # Apply the step activation function if weighted_sum > 0: output = 1 else: output = 0 return output # Define the inputs, weights, and bias for the AND operation inputs = np.array([1, 1]) # Input values weights = np.array([0.5, 0.5]) # Weight values bias = -1 # Bias value # Perform the calculation using the perceptron output = perceptron(inputs, weights, bias) # Print the output print("Output:", output) Result: In this example, we have defined the perceptron function that takes the inputs, weights, and bias as parameters. It calculates the weighted sum of the inputs, applies the step activation function, and returns the output. We then define the inputs as an array of [1, 1], weights as [0.5, 0.5], and bias as -1, which represents the logical AND operation. Finally, we call the perceptron function with the inputs, weights, and bias, and print the output. You can modify the inputs, weights, and bias to perform different calculations or implement other logical operations such as OR or XOR. Download 172.03 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling