diff options
Diffstat (limited to 'numpy/lib/index_tricks.py')
-rw-r--r-- | numpy/lib/index_tricks.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index e97338106..8bcc3fb53 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -7,7 +7,7 @@ import numpy.core.numeric as _nx from numpy.core.numeric import ( asarray, ScalarType, array, alltrue, cumprod, arange ) -from numpy.core.numerictypes import find_common_type +from numpy.core.numerictypes import find_common_type, issubdtype from . import function_base import numpy.matrixlib as matrix @@ -71,17 +71,17 @@ def ix_(*args): """ out = [] nd = len(args) - baseshape = [1]*nd - for k in range(nd): - new = _nx.asarray(args[k]) - if (new.ndim != 1): + for k, new in enumerate(args): + new = asarray(new) + if new.ndim != 1: raise ValueError("Cross index must be 1 dimensional") - if issubclass(new.dtype.type, _nx.bool_): - new = new.nonzero()[0] - baseshape[k] = len(new) - new = new.reshape(tuple(baseshape)) + if new.size == 0: + # Explicitly type empty arrays to avoid float default + new = new.astype(_nx.intp) + if issubdtype(new.dtype, _nx.bool_): + new, = new.nonzero() + new = new.reshape((1,)*k + (new.size,) + (1,)*(nd-k-1)) out.append(new) - baseshape[k] = 1 return tuple(out) class nd_grid(object): @@ -404,7 +404,7 @@ class RClass(AxisConcatenator): See Also -------- - concatenate : Join a sequence of arrays together. + concatenate : Join a sequence of arrays along an existing axis. c_ : Translates slice objects to concatenation along the second axis. Examples @@ -681,7 +681,7 @@ def fill_diagonal(a, val, wrap=False): wrap : bool For tall matrices in NumPy version up to 1.6.2, the diagonal "wrapped" after N columns. You can have this behavior - with this option. This affect only tall matrices. + with this option. This affects only tall matrices. See also -------- @@ -724,7 +724,9 @@ def fill_diagonal(a, val, wrap=False): [0, 0, 0], [0, 0, 4]]) - # tall matrices no wrap + The wrap option affects only tall matrices: + + >>> # tall matrices no wrap >>> a = np.zeros((5, 3),int) >>> fill_diagonal(a, 4) >>> a @@ -734,7 +736,7 @@ def fill_diagonal(a, val, wrap=False): [0, 0, 0], [0, 0, 0]]) - # tall matrices wrap + >>> # tall matrices wrap >>> a = np.zeros((5, 3),int) >>> fill_diagonal(a, 4, wrap=True) >>> a @@ -744,7 +746,7 @@ def fill_diagonal(a, val, wrap=False): [0, 0, 0], [4, 0, 0]]) - # wide matrices + >>> # wide matrices >>> a = np.zeros((3, 5),int) >>> fill_diagonal(a, 4, wrap=True) >>> a |