1
0
Fork 0
mirror of https://github.com/davrot/pytutorial.git synced 2025-04-19 05:36:42 +02:00

Update README.md

Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
David Rotermund 2023-12-15 10:03:15 +01:00 committed by GitHub
parent ce5325c47e
commit 64751246ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -173,7 +173,9 @@ A = np.zeros((4, 1, 9, 1)) # -> (4, 1, 9, 1)
print(A.shape)
B = A.squeeze(axis=1) # -> (4, 9, 1)
print(B.shape)
print(np.may_share_memory(A, B)) # -> True
```
## [numpy.moveaxis](https://numpy.org/doc/stable/reference/generated/numpy.moveaxis.html)
```python
@ -191,8 +193,89 @@ A = np.zeros((4, 1, 9, 1))
print(A.shape) # -> (4, 1, 9, 1)
B = np.moveaxis(A, 0, 1)
print(B.shape) # -> (1, 4, 9, 1)
print(np.may_share_memory(A, B)) # -> True
```
## [numpy.ndarray.swapaxes](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.swapaxes.html)
```python
ndarray.swapaxes(axis1, axis2)
```
> Return a **view** of the array with axis1 and axis2 interchanged.
```python
import numpy as np
A = np.zeros((4, 1, 9, 1))
print(A.shape) # -> (4, 1, 9, 1)
B = A.swapaxes(0, 1)
print(B.shape) # -> (1, 4, 9, 1)
print(np.may_share_memory(A, B)) # -> True
```
## [numpy.ndarray.T](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.T.html) (Transposing a 2d matrix)
```python
ndarray.T
```
> View of the transposed array.
>
> Same as self.transpose().
```python
import numpy as np
A = np.zeros((4, 9))
B = A.T
print(A.shape) # -> (4, 9)
print(B.shape) # -> (9, 4)
print(np.may_share_memory(A, B)) # -> True
```
## [numpy.ndarray.transpose](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.transpose.html)
{: .topic-optional}
This is an optional topic!
```python
ndarray.transpose(*axes)
```
> Returns a view of the array with axes transposed.
## [numpy.ndarray.flatten](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.flatten.html)
```python
ndarray.flatten(order='C')
```
> Return a **copy** of the array collapsed into one dimension.
```python
import numpy as np
A = np.arange(0, 6)
A = A.reshape((2, 3))
print(A)
print()
B = A.flatten()
print(B)
print(np.may_share_memory(A, B)) # -> False
```
Output:
```python
[[0 1 2]
[3 4 5]]
[0 1 2 3 4 5]
```
## [Array methods](https://numpy.org/doc/stable/reference/arrays.ndarray.html#array-methods)
### [Array conversion](https://numpy.org/doc/stable/reference/arrays.ndarray.html#array-conversion)