Update README.md

Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
David Rotermund 2023-12-19 10:58:34 +01:00 committed by GitHub
parent 92f9f42b6d
commit 9054ad98e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
```