-
-
Notifications
You must be signed in to change notification settings - Fork 130
Create neuron.md #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create neuron.md #215
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please read the guidelines in CONTRIBUTING.md before submitting any snippets, Tags shouldn't contain the name of the language they are coded in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding typing to function could be great too ! |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow proper formatting of snippets, using |
||
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}") | ||
``` |