-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[Term Entry] PyTorch Tensors: .randn() #4956
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
94cc9de
created entry of PyTorch Tensors .randn()
ompharate e42263e
Merge branch 'main' into randn.md
ompharate be83630
Merge branch 'main' into randn.md
ompharate db1cba7
Update `.randn()` documentation: Add detailed parameter descriptions
ompharate 3d3275b
Merge branch 'main' into randn.md
ompharate f491903
Merge branch 'main' into randn.md
cigar-galaxy82 5dd03f6
fix: add blank line
ompharate 30decc0
Merge branch 'main' into randn.md
cigar-galaxy82 f9eda65
Update randn.md
mamtawardhani 2104189
Update catalog-content.md
mamtawardhani d4ed43e
Update randn.md
mamtawardhani 05b5aef
Update randn.md
mamtawardhani 9f21d49
Merge branch 'main' into randn.md
mamtawardhani f00c491
Update randn.md
mamtawardhani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,49 @@ | ||
--- | ||
Title: '.randn()' | ||
Description: 'Generates a tensor with random numbers drawn from a normal distribution.' | ||
Subjects: | ||
- 'Data Science' | ||
- 'Machine Learning' | ||
Tags: | ||
- 'PyTorch' | ||
- 'Tensors' | ||
CatalogContent: | ||
- 'intro-to-py-torch-and-neural-networks' | ||
- 'py-torch-for-classification' | ||
mamtawardhani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--- | ||
|
||
The **`.randn()`** function in PyTorch generates a tensor with random numbers drawn from a normal distribution with a mean of _0_ and a standard deviation of _1_. This function is particularly useful for initializing weights in neural networks and for other purposes requiring randomized data, especially in machine learning applications. | ||
|
||
## Syntax | ||
|
||
```pseudo | ||
torch.randn(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) | ||
``` | ||
|
||
- `*size`: Specifies the shape of the output tensor. This can be one or more integers, defining the dimensions of the tensor. | ||
- `out` (optional): A tensor where the result will be stored. If specified, the output is stored in this tensor; otherwise, a new tensor is created. | ||
- `dtype` (optional): The desired data type of the returned tensor. | ||
- `layout` (optional): The desired layout of the returned tensor. The default is `torch.strided`. | ||
- `device` (optional): The device on which the tensor is allocated. | ||
- `requires_grad` (optional): If set to `True`, PyTorch will track operations on the tensor for automatic differentiation. Defaults to `False`. | ||
|
||
## Example | ||
|
||
The following example uses `.randn()` to create a 4x4 tensor with random values from a normal distribution: | ||
|
||
```py | ||
import torch | ||
tensor = torch.randn(4, 4) | ||
print(tensor) | ||
``` | ||
|
||
This produces the following output: | ||
|
||
```shell | ||
tensor([[-0.7484, 1.2086, 0.3430, 0.6699], | ||
[ 0.7022, 0.0815, 0.4855, 0.1603], | ||
[-0.1214, 0.2484, 1.5672, -0.7005], | ||
[ 1.3106, -0.6518, 0.7351, -0.1027]]) | ||
``` | ||
|
||
mamtawardhani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
**Note:** This code will generate a different random output each time it is run, as `.randn()` produces random values from a normal distribution. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.