From 21d55e2ce8ef45e5d63edca582d679c14d06b52b Mon Sep 17 00:00:00 2001 From: jimmydin7 <129774378+jimmydin7@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:35:21 +0200 Subject: [PATCH] Create neuron.md --- snippets/python/math-and-numbers/neuron.md | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 snippets/python/math-and-numbers/neuron.md diff --git a/snippets/python/math-and-numbers/neuron.md b/snippets/python/math-and-numbers/neuron.md new file mode 100644 index 00000000..497c813f --- /dev/null +++ b/snippets/python/math-and-numbers/neuron.md @@ -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}") +```