Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
jimmydin7 wants to merge 1 commit into quicksnip-dev:main from jimmydin7:patch-1
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Create neuron.md
  • Loading branch information
jimmydin7 authored Jan 8, 2025
commit 21d55e2ce8ef45e5d63edca582d679c14d06b52b
29 changes: 29 additions & 0 deletions snippets/python/math-and-numbers/neuron.md
View file Open in desktop
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
Copy link
Collaborator

@Mathys-Gasnier Mathys-Gasnier Jan 8, 2025

Choose a reason for hiding this comment

The 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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding typing to function could be great too !

Mathys-Gasnier reacted with thumbs up emoji
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
Copy link
Collaborator

@Mathys-Gasnier Mathys-Gasnier Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow proper formatting of snippets, using # Usage: for the usage section.
Could you also improve the example a bit ? There is some text that's not in a comment, and you could add a comment showing what the result of a calculation is/looks like

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}")
```

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /