-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Edited Python Numpy built-in functions .reshape() #5523
base: main
Are you sure you want to change the base?
Conversation
Hello @mamtawardhani , A new PR was launched |
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.
Hey @NelsonSanti thank you for contributing to Codecademy Docs! 😄
I've suggested a few changes, could you review and modify those at your earliest convenience? Thank you!
Optionally, a third parameter can be added to the syntax: `order`. | ||
|
||
`order` reads the elements from `array` in the current index order and places the elements into the reshaped array using the same index order. It can be set to `'C'`, `'F'`, or `'A'`. `C` means to read/write the elements using C-like index order, or in other words, the elements are placed row by row. The last axis index (columns) changes first (fastest), and the first axis index (rows) changes afterward (slowest). `F` means to read/write the elements using Fortran-like index order, where the elements are placed column by column. Here, the first axis index (rows) changes faster while the last axis index (columns) changes slower. Using `C` or `F` in `.reshape()` means that the function is only reshaping the way that indexes are placed in the array, and not like data physically stored in the computer memory (memory layout). `A` means to read/write the elements in Fortran-like index order if `array` is Fortran contiguous in memory, meaning, in a sequencial and continuous manner without gaps between elements, or in C-like index order otherwise. | ||
|
||
```pseudo | ||
numpy.reshape(array, newshape, order = 'C') | ||
``` |
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.
This can be edited in the ##Syntax section itself. @NelsonSanti What we can do is, go to the ## Syntax section above, modify that syntax by adding the order
parameter as well. Then after the syntax, use bullet points to address the parameters. Example:
numpy.reshape(array, newshape, order = 'C')
array
: Describe thisnewshape
: describe thisorder
: Describe thisC
: describeF
: describeA
: descibe
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.
This way a proper structure can be maintained
```pseudo | ||
numpy.reshape(array, newshape, order = 'C') | ||
``` | ||
|
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.
## Codebyte Example |
|
||
The following example creates an `ndarray` then uses `order` as an optional parameter for `.reshape()` to change its dimensions. | ||
|
||
```py |
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.
```py | |
```codebyte/python |
This produces the following output: | ||
|
||
```shell | ||
[[10 20 30] | ||
[40 50 60]] | ||
|
||
|
||
[[10 20] | ||
[30 40] | ||
[50 60]] | ||
|
||
|
||
[[10 50] | ||
[40 30] | ||
[20 60]] | ||
``` | ||
|
||
> [!Note] | ||
> The last output just reflects the natural behaviour from Fortran indexation order |
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.
This produces the following output: | |
```shell | |
[[10 20 30] | |
[40 50 60]] | |
[[10 20] | |
[30 40] | |
[50 60]] | |
[[10 50] | |
[40 30] | |
[20 60]] | |
``` | |
> [!Note] | |
> The last output just reflects the natural behaviour from Fortran indexation order |
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.
Codebyte examples are not to be accompanied by output blocks, so we can remove this
Hello @mamtawardhani , |
Description
Issue Solved
Closes issue #5374
Type of Change
Checklist
main
branch.Issues Solved
section.