summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index ca5ef62ae..20e32a78d 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -268,6 +268,19 @@ def iterable(y):
>>> np.iterable(2)
False
+ Notes
+ -----
+ In most cases, the results of ``np.iterable(obj)`` are consistent with
+ ``isinstance(obj, collections.abc.Iterable)``. One notable exception is
+ the treatment of 0-dimensional arrays::
+
+ >>> from collections.abc import Iterable
+ >>> a = np.array(1.0) # 0-dimensional numpy array
+ >>> isinstance(a, Iterable)
+ True
+ >>> np.iterable(a)
+ False
+
"""
try:
iter(y)
@@ -657,11 +670,16 @@ def select(condlist, choicelist, default=0):
Examples
--------
- >>> x = np.arange(10)
- >>> condlist = [x<3, x>5]
+ >>> x = np.arange(6)
+ >>> condlist = [x<3, x>3]
>>> choicelist = [x, x**2]
- >>> np.select(condlist, choicelist)
- array([ 0, 1, 2, ..., 49, 64, 81])
+ >>> np.select(condlist, choicelist, 42)
+ array([ 0, 1, 2, 42, 16, 25])
+
+ >>> condlist = [x<=4, x>3]
+ >>> choicelist = [x, x**2]
+ >>> np.select(condlist, choicelist, 55)
+ array([ 0, 1, 2, 3, 4, 25])
"""
# Check the size of condlist and choicelist are the same, or abort.
@@ -4740,9 +4758,8 @@ def insert(arr, obj, values, axis=None):
if indices.size == 1:
index = indices.item()
if index < -N or index > N:
- raise IndexError(
- "index %i is out of bounds for axis %i with "
- "size %i" % (obj, axis, N))
+ raise IndexError(f"index {obj} is out of bounds for axis {axis} "
+ f"with size {N}")
if (index < 0):
index += N