Update README.md
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
parent
92f9f42b6d
commit
9054ad98e3
1 changed files with 16 additions and 0 deletions
|
@ -123,3 +123,19 @@ print(type(data[0:1, 0:1, 0:1])) # -> <class 'numpy.ndarray'>
|
|||
|
||||
**Please understand this creates a view which is connected to original data.** If necessary make a **copy()**.
|
||||
|
||||
## Adding dimensions with np.newaxis
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
data = np.zeros((2))
|
||||
print(data.shape) # -> (2,)
|
||||
print(data[:, np.newaxis].shape) # -> (2, 1)
|
||||
print(data[np.newaxis, :].shape) # -> (1, 2)
|
||||
|
||||
|
||||
print(data[:, np.newaxis, np.newaxis].shape) # -> (2, 1, 1)
|
||||
print(data[np.newaxis, :, np.newaxis].shape) # -> (1, 2, 1)
|
||||
print(data[:, np.newaxis, np.newaxis].shape) # -> (2, 1, 1)
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue