From 5d70de730b7b3f1586826f708a9c0cda37d95511 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 18 Nov 2021 00:05:01 +0100 Subject: Document what len(a) is in See Also of numpy.shape --- numpy/core/fromnumeric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/core/fromnumeric.py') diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 3242124ac..3e2d49c8b 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1980,7 +1980,7 @@ def shape(a): See Also -------- - len + len : ``len(a)`` is equivalent to ``np.shape(a)[0]`` for 1+-dim arrays. ndarray.shape : Equivalent array method. Examples -- cgit v1.2.1 From 60999d5af0fa142cabe67381e0033b203de3f083 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 18 Nov 2021 00:07:55 +0100 Subject: Make numpy.shape examples less ambiguous - The shape shound not coincidetially contain the same numbers as the data - For structured arrays, the shape should not coincide with the number of fields --- numpy/core/fromnumeric.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'numpy/core/fromnumeric.py') diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 3e2d49c8b..a65a019c0 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1987,18 +1987,19 @@ def shape(a): -------- >>> np.shape(np.eye(3)) (3, 3) - >>> np.shape([[1, 2]]) + >>> np.shape([[1, 3]]) (1, 2) >>> np.shape([0]) (1,) >>> np.shape(0) () - >>> a = np.array([(1, 2), (3, 4)], dtype=[('x', 'i4'), ('y', 'i4')]) + >>> a = np.array([(1, 2), (3, 4), (5, 6)], + dtype=[('x', 'i4'), ('y', 'i4')]) >>> np.shape(a) - (2,) + (3,) >>> a.shape - (2,) + (3,) """ try: -- cgit v1.2.1 From 5ff2462e2c0172eb6d319c95140dd8b079aaf226 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 18 Nov 2021 00:15:58 +0100 Subject: Improve See Also of ndarray.shape --- numpy/core/fromnumeric.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'numpy/core/fromnumeric.py') diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index a65a019c0..9b51b391a 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1980,7 +1980,8 @@ def shape(a): See Also -------- - len : ``len(a)`` is equivalent to ``np.shape(a)[0]`` for 1+-dim arrays. + len : ``len(a)`` is equivalent to ``np.shape(a)[0]`` for N-D arrays with + ``N>=1``. ndarray.shape : Equivalent array method. Examples @@ -1995,7 +1996,7 @@ def shape(a): () >>> a = np.array([(1, 2), (3, 4), (5, 6)], - dtype=[('x', 'i4'), ('y', 'i4')]) + ... dtype=[('x', 'i4'), ('y', 'i4')]) >>> np.shape(a) (3,) >>> a.shape -- cgit v1.2.1