8000 Merge pull request #14932 from mproszewska/doc-tolist · numpy/numpy@2c14c5b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c14c5b

Browse files
authored
Merge pull request #14932 from mproszewska/doc-tolist
DOC: Compare 'tolist' function to 'list' in example
2 parents 5923592 + 9f6c1cc commit 2c14c5b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

numpy/core/_add_newdocs.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,15 +3953,22 @@
39533953
39543954
Examples
39553955
--------
3956-
For a 1D array, ``a.tolist()`` is almost the same as ``list(a)``:
3956+
For a 1D array, ``a.tolist()`` is almost the same as ``list(a)``,
3957+
except that ``tolist`` changes numpy scalars to Python scalars:
39573958
3958-
>>> a = np.array([1, 2])
3959-
>>> list(a)
3959+
>>> a = np.uint32([1, 2])
3960+
>>> a_list = list(a)
3961+
>>> a_list
39603962
[1, 2]
3961-
>>> a.tolist()
3963+
>>> type(a_list[0])
3964+
<class 'numpy.uint32'>
3965+
>>> a_tolist = a.tolist()
3966+
>>> a_tolist
39623967
[1, 2]
3968+
>>> type(a_tolist[0])
3969+
<class 'int'>
39633970
3964-
However, for a 2D array, ``tolist`` applies recursively:
3971+
Additionally, for a 2D array, ``tolist`` applies recursively:
39653972
39663973
>>> a = np.array([[1, 2], [3, 4]])
39673974
>>> list(a)
@@ -4246,7 +4253,7 @@
42464253
42474254
See Also
42484255
--------
4249-
vectorize : evaluates pyfunc over input arrays using broadcasting rules of numpy
4256+
vectorize : Evaluates pyfunc over input arrays using broadcasting rules of numpy.
42504257
42514258
Notes
42524259
-----

0 commit comments

Comments
 (0)
0