-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
title: Basic Neuron Class | ||
description: A Python class representing a single artificial neuron that computes the weighted sum of inputs and applies an optional activation function. | ||
tags: python, machine-learning, neural-networks | ||
author: jimmydin7 | ||
--- | ||
|
||
```py | ||
import numpy as np | ||
|
||
class Neuron: | ||
def __init__(self, inputs, weights, bias): | ||
self.inputs = inputs | ||
self.weights = weights | ||
self.bias = bias | ||
|
||
def get_output(self): | ||
weighted_sum = np.dot(self.inputs, self.weights) + self.bias | ||
return weighted_sum | ||
|
||
# Example usage | ||
inputs = np.array([1.0, 2.0, 3.0]) | ||
weights = np.array([0.2, 0.8, -0.5]) | ||
bias = 2.0 | ||
|
||
neuron = Neuron(inputs, weights, bias) | ||
output = neuron.get_output() (you can add an activation function) | ||
print(f"Neuron output: {output}") | ||
``` |