# numpy/numpy

Merge changes to the trunk to this branch.

teoliphant committed Dec 30, 2007
1 parent 89d0310 commit 50b26d2464f607566bf66986832636816eaa6d05
Showing with 397 additions and 38 deletions.
1. +6 −3 arraysetops.py
2. +2 −2 getlimits.py
3. +18 −16 index_tricks.py
4. +359 −7 scimath.py
5. +4 −0 tests/test_arraysetops.py
6. +4 −6 tests/test_getlimits.py
7. +4 −4 tests/test_polynomial.py
 @@ -201,9 +201,13 @@ def setmember1d( ar1, ar2 ): numpy.lib.arraysetops has a number of other functions for performing set operations on arrays. """ - zlike = nm.zeros_like + ar1 = nm.asarray( ar1 ) + ar2 = nm.asarray( ar2 ) ar = nm.concatenate( (ar1, ar2 ) ) - tt = nm.concatenate( (zlike( ar1 ), zlike( ar2 ) + 1) ) + b1 = nm.zeros( ar1.shape, dtype = nm.int8 ) + b2 = nm.ones( ar2.shape, dtype = nm.int8 ) + tt = nm.concatenate( (b1, b2) ) + # We need this to be a stable sort, so always use 'mergesort' here. The # values from the first array should always come before the values from the # second array. @@ -212,7 +216,6 @@ def setmember1d( ar1, ar2 ): aux2 = tt[perm] # flag = ediff1d( aux, 1 ) == 0 flag = nm.concatenate( (aux[1:] == aux[:-1], [False] ) ) - ii = nm.where( flag * aux2 )[0] aux = perm[ii+1] perm[ii+1] = perm[ii]
 @@ -7,7 +7,7 @@ import numpy.core.numeric as numeric import numpy.core.numerictypes as ntypes from numpy.core.numeric import array -import numpy as N +import numpy as np def _frz(a): """fix rank-0 --> rank-1""" @@ -128,7 +128,7 @@ class iinfo: _max_vals = {} def __init__(self, type): - self.dtype = N.dtype(type) + self.dtype = np.dtype(type) self.kind = self.dtype.kind self.bits = self.dtype.itemsize * 8 self.key = "%s%d" % (self.kind, self.bits)
 @@ -1,5 +1,3 @@ -## Automatically adapted for numpy Sep 19, 2005 by convertcode.py - __all__ = ['unravel_index', 'mgrid', 'ogrid', @@ -48,7 +46,7 @@ def unravel_index(x,dims): # Reverse # [dcb,dc,d,1] dim_prod = _nx.cumprod([1] + list(dims)[:0:-1])[::-1] - # Indeces become [x/dcb % a, x/dc % b, x/d % c, x/1 % d] + # Indices become [x/dcb % a, x/dc % b, x/d % c, x/1 % d] return tuple(x/dim_prod % dims) def ix_(*args): @@ -193,7 +191,7 @@ def __len__(self): mgrid = nd_grid(sparse=False) ogrid = nd_grid(sparse=True) -class concatenator(object): +class AxisConcatenator(object): """Translates slice objects to concatenation along an axis. """ def _retval(self, res): @@ -313,26 +311,30 @@ def __len__(self): # etc. because otherwise we couldn't get the doc string to come out right # in help(r_) -class r_class(concatenator): +class RClass(AxisConcatenator): """Translates slice objects to concatenation along the first axis. - For example: - >>> r_[array([1,2,3]), 0, 0, array([4,5,6])] - array([1, 2, 3, 0, 0, 4, 5, 6]) + For example: + >>> r_[array([1,2,3]), 0, 0, array([4,5,6])] + array([1, 2, 3, 0, 0, 4, 5, 6]) """ def __init__(self): - concatenator.__init__(self, 0) + AxisConcatenator.__init__(self, 0) -r_ = r_class() +r_ = RClass() -class c_class(concatenator): +class CClass(AxisConcatenator): """Translates slice objects to concatenation along the second axis. + + For example: + >>> c_[array([[1,2,3]]), 0, 0, array([[4,5,6]])] + array([1, 2, 3, 0, 0, 4, 5, 6]) """ def __init__(self): - concatenator.__init__(self, -1, ndmin=2, trans1d=0) + AxisConcatenator.__init__(self, -1, ndmin=2, trans1d=0) -c_ = c_class() +c_ = CClass() class ndenumerate(object): """ @@ -423,7 +425,7 @@ def __iter__(self): # # -class _index_expression_class(object): +class IndexExpression(object): """ A nicer way to build up index tuples for arrays. @@ -451,7 +453,7 @@ def __getslice__(self, start, stop): stop = None return self[start:stop:None] -index_exp = _index_expression_class(1) -s_ = _index_expression_class(0) +index_exp = IndexExpression(maketuple=True) +s_ = IndexExpression(maketuple=False) # End contribution from Konrad.