From 6359dccac9d940dc3291de360b4cb377183e1b9d Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Thu, 14 Sep 2006 01:20:52 +0000 Subject: Fix column-stack to not transpose 2-d inputs. Fix iscomplex for strings. Add deprecation warning for c_ --- numpy/lib/index_tricks.py | 17 ++++++++--------- numpy/lib/shape_base.py | 18 +++++++++++++----- numpy/lib/type_check.py | 8 ++++++-- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index 0835a69fd..6c864080f 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -225,7 +225,7 @@ class concatenator(object): if start is None: start = 0 if step is None: step = 1 - if type(step) is type(1j): + if isinstance(step, complex): size = int(abs(step)) newobj = function_base.linspace(start, stop, num=size) else: @@ -281,18 +281,20 @@ class r_class(concatenator): r_ = r_class() +import warnings + class c_class(concatenator): """Translates slice objects to concatenation along the second axis. - For example: - >>> c_[array([[1],[2],[3]]), array([[4],[5],[6]])] - array([[1, 4], - [2, 5], - [3, 6]]) + This is deprecated. Use r_[...,'-1'] """ def __init__(self): concatenator.__init__(self, -1) + def __getitem__(self, obj): + warnings.warn("c_ is deprecated use r_[...,'-1']") + return concatenator.__getitem__(self, obj) + c_ = c_class() class ndenumerate(object): @@ -383,9 +385,6 @@ class ndindex(object): # Cosmetic changes by T. Oliphant 2001 # # -# This module provides a convenient method for constructing -# array indices algorithmically. It provides one importable object, -# 'index_expression'. class _index_expression_class(object): """ diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index d44215446..fa03a5127 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -141,7 +141,7 @@ def atleast_2d(*arys): """ res = [] for ary in arys: - res.append(array(ary,copy=False,subok=2,ndmin=2)) + res.append(array(ary,copy=False,subok=True,ndmin=2)) if len(res) == 1: return res[0] else: @@ -246,10 +246,13 @@ def column_stack(tup): Description: Take a sequence of 1D arrays and stack them as columns to make a single 2D array. All arrays in the sequence - must have the same length. + must have the same first dimension. 2D arrays are + stacked as-is, just like with hstack. 1D arrays are turned + into 2D columns first. + Arguments: - tup -- sequence of 1D arrays. All arrays must have the same - length. + tup -- sequence of 1D or 2D arrays. All arrays must have the same + first dimension. Examples: >>> import numpy >>> a = array((1,2,3)) @@ -260,7 +263,12 @@ def column_stack(tup): [3, 4]]) """ - arrays = map(_nx.transpose,map(atleast_2d,tup)) + arrays = [] + for v in tup: + arr = array(v,copy=False,subok=True) + if arr.ndim < 2: + arr = array(arr,copy=False,subok=True,ndmin=2).T + arrays.append(arr) return _nx.concatenate(arrays,1) def dstack(tup): diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py index 0954bbf89..ec6159123 100644 --- a/numpy/lib/type_check.py +++ b/numpy/lib/type_check.py @@ -6,7 +6,7 @@ __all__ = ['iscomplexobj','isrealobj','imag','iscomplex', 'common_type'] import numpy.core.numeric as _nx -from numpy.core.numeric import asarray, array, isnan, obj2sctype +from numpy.core.numeric import asarray, array, isnan, obj2sctype, zeros from ufunclike import isneginf, isposinf _typecodes_by_elsize = 'GDFgdfQqLlIiHhBb?' @@ -68,7 +68,11 @@ def iscomplex(x): For scalars, return a boolean. """ - return imag(x) != 0 + ax = asarray(x) + if issubclass(ax.dtype.type, _nx.complexfloating): + return ax.imag != 0 + res = zeros(ax.shape, bool) + return +res # convet to array-scalar if needed def isreal(x): """Return a boolean array where elements are True if that element -- cgit v1.2.1