Update README.md

Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
David Rotermund 2023-12-30 18:43:36 +01:00 committed by GitHub
parent 0ad5c72ef6
commit 4ca3ced758
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,3 +64,37 @@ Output:
[3 4 5 6 7]]
```
## This is not [numpy.ndarray.resize](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.resize.html#numpy.ndarray.resize)
```python
ndarray.resize(new_shape, refcheck=True)
```
> Change shape and size of array in-place.
I added a copy because it does not work on views (*ValueError: cannot resize this array: it does not own its data*) , which reshape creates.
```python
import numpy as np
a = np.arange(1, 10).reshape((3, 3)).copy()
print(a)
print()
a.resize((5, 5))
print(a)
```
Output:
```python
[[1 2 3]
[4 5 6]
[7 8 9]]
[[1 2 3 4 5]
[6 7 8 9 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]]
```