-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
New term entry on the built in function for Numpy named 'svd' #4547
Merged
letsbuildanything
merged 16 commits into
Codecademy:main
from
doroodianMostafa:svd-branch
May 26, 2024
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7798cd4
new term entry on the built in function for Numpy named svd (Singular…
doroodian 048e810
Merge branch 'main' into svd-branch
doroodianMostafa 16a04c7
Merge branch 'Codecademy:main' into svd-branch
doroodianMostafa 9bb20ac
Changes made respecting mamtawardhani suggestion
doroodian 351605c
tailoring the SVD example according the provided link by mamtawardhani
doroodian d0334b1
adding the output block and additional suggestions by mamtawardhani
doroodian 6b72655
Merge branch 'main' into svd-branch
doroodianMostafa 2290034
minor changes
letsbuildanything 834ecf2
Update svd.md
letsbuildanything d009c71
adding codebyte and fixing spelling mistake.
doroodian 66aa123
solving merg conflict problem
doroodian 84002bd
Applying Pankaj\'s lost changes
doroodian d62a5c8
fix formatting
letsbuildanything 6af1f6c
Update svd.md
letsbuildanything 37b9b44
Merge branch 'main' into svd-branch
letsbuildanything bc9a7f3
add removed line
letsbuildanything File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
content/numpy/concepts/built-in-functions/terms/svd/svd.md
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,51 @@ | ||||||
--- | ||||||
Title: '.svd()' | ||||||
Description: 'The `.svd()` built-in function performs the Singular Value Decomposition (SVD) on a matrix, breaking it down into singular vectors and values.' | ||||||
Subjects: | ||||||
- 'Computer Science' | ||||||
- 'Data Science' | ||||||
- 'Machine Learning' | ||||||
Tags: | ||||||
- 'Linear Algebra' | ||||||
- 'Machine Learning' | ||||||
- 'NumPy' | ||||||
CatalogContent: | ||||||
- 'learn-python-3' | ||||||
- 'paths/computer-science' | ||||||
- 'paths/data-science' | ||||||
- 'paths/data-science-foundaions' | ||||||
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.
Suggested change
|
||||||
--- | ||||||
|
||||||
The **`.svd()`** function is a mathematical technique that decomposes a matrix into three simpler matrices: it factorizes the matrix `a` into two unitary matrices `U` and `Vh`, along with a 1-D array `s` of singular values (real and non-negative). This decomposition satisfies the equation `a = U @ S @ Vh`, where `S` is a suitably shaped matrix of zeros with `s` as its main diagonal. | ||||||
## Syntax | ||||||
mamtawardhani marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
```pseudo | ||||||
numpy.linalg.svd(a, full_matrices=True, compute_uv=True, hermitian=False) | ||||||
``` | ||||||
`.svd()` provides the following arguments: | ||||||
mamtawardhani marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
- `a`: This parameter represents the input matrix to be decomposed, where `a.ndim>=2`. It is the matrix on which Singular Value Decomposition will be performed. | ||||||
- `full_matrices`: This parameter determines whether the function computes full-sized or reduced-sized matrices `U` and `Vh`. If `full_matrices` is set to `True`, the function computes the full-sized matrices. If set to `False`, it computes only the essential parts of `U` and `Vh`. The default value is `True`. | ||||||
- `compute_uv`: This parameter specifies whether the function computes the left-singular vectors (`U`) and right-singular vectors (transpose of `V`) in addition to the singular values. When `compute_uv` is set to `True`, the function computes `U` and `Vh`. If set to `False`, it only computes the singular values. The default value is `True`. | ||||||
- `hermitian`: This parameter indicates whether the input matrix `a` is Hermitian, meaning it is equal to its conjugate transpose. When `hermitian` is set to `True`, the function assumes that a is Hermitian and uses a more efficient algorithm tailored for such matrices. If set to `False`, it uses a general algorithm. The default value is `False`. | ||||||
|
||||||
## Example | ||||||
The following example demonstrates various scenarios of Singular Value Decomposition (SVD) and uses `.svd()` using `NumPy`: | ||||||
|
||||||
```py | ||||||
# The following example demonstrates a scenario of Singular Value Decomposition (SVD) for a 2D matrix using NumPy: | ||||||
import numpy as np | ||||||
|
||||||
# Create a 2D array | ||||||
A = np.random.randn(5, 3) # Creating a random 2D matrix | ||||||
|
||||||
print("Original 2D matrix:") | ||||||
print(A) | ||||||
|
||||||
# Compute the factor by Singular Value Decomposition | ||||||
U, S, V = np.linalg.svd(A) | ||||||
|
||||||
# Print the result | ||||||
print("\nFactor of the given array by Singular Value Decomposition:") | ||||||
print("\nU=", U, "\n\ns=", S, "\n\nV=", V) | ||||||
``` | ||||||
mamtawardhani marked this conversation as resolved.
Show resolved
Hide resolved
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 add a codebyte example below. For more information on how to write it, visit here. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.