diff --git a/numpy/dimensions/README.md b/numpy/dimensions/README.md index 0457575..ae52c4f 100644 --- a/numpy/dimensions/README.md +++ b/numpy/dimensions/README.md @@ -54,6 +54,19 @@ print(data[0, 0, :].shape) # -> (2,) print(data[0, 0, 0].shape) # -> () print(type(data[0, 0, 0])) # -> ``` +### keepdims + +There are functions like +```python +ndarray.sum(axis=None, dtype=None, out=None, keepdims=False, initial=0, where=True) +ndarray.mean(axis=None, dtype=None, out=None, keepdims=False, *, where=True) +ndarray.prod(axis=None, dtype=None, out=None, keepdims=False, initial=1, where=True) +ndarray.max(axis=None, out=None, keepdims=False, initial=, where=True) +ndarray.min(axis=None, out=None, keepdims=False, initial=, where=True) +ndarray.argmax(axis=None, out=None, *, keepdims=False) +ndarray.argmin(axis=None, out=None, *, keepdims=False) +``` +that normally make one dimension vanish. However, often this type of functions have an argument **keepdims** that keeps this dimension alive. ```python import numpy as np @@ -74,4 +87,12 @@ print(data.sum(axis=1, keepdims=True).shape) # -> (5, 1, 2) print(data.sum(axis=2, keepdims=True).shape) # -> (5, 3, 1) ``` +As as reminder, shape is only availabe for np.ndarray and torch.Tensor matrices: +```python +z = int(7) +print(np.array(z).shape) # -> () +print(type(np.array(z))) # -> +print(type(z)) # -> +print(z.shape) # -> AttributeError: 'int' object has no attribute 'shape' +```