[Numpy-svn] r3225 - in trunk/numpy: core numarray oldnumeric
numpy-svn at scipy.org
numpy-svn at scipy.org
Thu Sep 28 05:56:53 EDT 2006
Author: oliphant
Date: 2006-09-28 04:56:41 -0500 (Thu, 28 Sep 2006)
New Revision: 3225
Modified:
trunk/numpy/core/info.py
trunk/numpy/core/numeric.py
trunk/numpy/numarray/functions.py
trunk/numpy/oldnumeric/functions.py
trunk/numpy/oldnumeric/misc.py
Log:
Fix the fromfunction routine to use float as default. Update oldnumeric and numarray compatibility modules.
Modified: trunk/numpy/core/info.py
===================================================================
--- trunk/numpy/core/info.py 2006-09-28 02:22:21 UTC (rev 3224)
+++ trunk/numpy/core/info.py 2006-09-28 09:56:41 UTC (rev 3225)
@@ -16,7 +16,7 @@
- reshape - Return array with new shape
- repeat - Repeat elements of array
- choose - Construct new array from indexed array tuple
-- cross_correlate - Correlate two 1-d arrays
+- correlate - Correlate two 1-d arrays
- searchsorted - Search for element in 1-d array
- sum - Total sum over a specified dimension
- average - Average, possibly weighted, over axis or array.
@@ -29,9 +29,8 @@
More Functions:
-- arrayrange (arange) - Return regularly spaced array
+- arange - Return regularly spaced array
- asarray - Guarantee NumPy array
-- sarray - Guarantee a NumPy array that keeps precision
- convolve - Convolve two 1-d arrays
- swapaxes - Exchange axes
- concatenate - Join arrays together
@@ -40,9 +39,9 @@
- argsort - Indices of sorted array
- argmax - Index of largest value
- argmin - Index of smallest value
-- innerproduct - Innerproduct of two arrays
+- inner - Innerproduct of two arrays
- dot - Dot product (matrix multiplication)
-- outerproduct - Outerproduct of two arrays
+- outer - Outerproduct of two arrays
- resize - Return array with arbitrary new shape
- indices - Tuple of indices
- fromfunction - Construct array from universal function
Modified: trunk/numpy/core/numeric.py
===================================================================
--- trunk/numpy/core/numeric.py 2006-09-28 02:22:21 UTC (rev 3224)
+++ trunk/numpy/core/numeric.py 2006-09-28 09:56:41 UTC (rev 3225)
@@ -448,17 +448,21 @@
lst.append( add.accumulate(tmp, i, dtype)-1 )
return array(lst)
-def fromfunction(function, dimensions, **kwargs):
- """fromfunction(function, dimensions, dtype=int) returns an array constructed by
- calling function on a tuple of number grids. The function should
- accept as many arguments as there are dimensions which is a list of
- numbers indicating the length of the desired output for each axis.
+def fromfunction(function, shape, **kwargs):
+ """returns an array constructed by calling a function on a tuple
+ of number grids. The function should accept as many arguments as the
+ length of shape and work on array inputs. The shape argument is a
+ sequence of numbers indicating the length of the desired output
+ for each axis.
- The function can also accept keyword arguments which will be
- passed in as well.
+ The function can also accept keyword arguments (except dtype),
+ which will be passed through fromfunction to the function itself.
+ The dtype argument (default float) determines the data-type of
+ the index grid passed to the function.
+
"""
- dtype = kwargs.get('dtype', int)
- args = indices(dimensions,dtype=dtype)
+ dtype = kwargs.pop('dtype', float)
+ args = indices(shape, dtype=dtype)
return function(*args,**kwargs)
def isscalar(num):
Modified: trunk/numpy/numarray/functions.py
===================================================================
--- trunk/numpy/numarray/functions.py 2006-09-28 02:22:21 UTC (rev 3224)
+++ trunk/numpy/numarray/functions.py 2006-09-28 09:56:41 UTC (rev 3225)
@@ -43,7 +43,7 @@
from numpy import dot as matrixmultiply, dot, vdot, ravel, concatenate, all,\
allclose, any, around, argsort, array_equal, array_equiv,\
array_str, array_repr, CLIP, RAISE, WRAP, clip, concatenate, \
- diagonal, e, pi, fromfunction, indices, inner as innerproduct, nonzero, \
+ diagonal, e, pi, indices, inner as innerproduct, nonzero, \
outer as outerproduct, kron as kroneckerproduct, lexsort, putmask, rank, \
resize, searchsorted, shape, size, sort, swapaxes, trace, transpose
import numpy as N
@@ -67,9 +67,12 @@
else:
dtype = N.dtype(type)
if use_default and dtype is None:
- dtype = N.dtype(None)
+ dtype = N.dtype('int')
return dtype
-
+
+def fromfunction(shape, dimensions, type=None, typecode=None, dtype=None):
+ dtype = type2dtype(typecode, type, dtype, 1)
+ return N.fromfunction(shape, dimensions, dtype=dtype)
def ones(shape, type=None, typecode=None, dtype=None):
dtype = type2dtype(typecode, type, dtype, 1)
return N.ones(shape, dtype)
Modified: trunk/numpy/oldnumeric/functions.py
===================================================================
--- trunk/numpy/oldnumeric/functions.py 2006-09-28 02:22:21 UTC (rev 3224)
+++ trunk/numpy/oldnumeric/functions.py 2006-09-28 09:56:41 UTC (rev 3225)
@@ -6,7 +6,7 @@
from typeconv import convtypecode, convtypecode2
__all__ = ['take', 'repeat', 'sum', 'product', 'sometrue', 'alltrue',
- 'cumsum', 'cumproduct', 'compress',
+ 'cumsum', 'cumproduct', 'compress', 'fromfunction',
'ones', 'empty', 'identity', 'zeros', 'array', 'asarray',
'nonzero', 'reshape', 'arange', 'fromstring', 'ravel', 'trace',
'indices', 'where','sarray','cross_product', 'argmax', 'argmin',
@@ -44,7 +44,10 @@
def compress(condition, m, axis=-1):
return N.compress(condition, m, axis)
-
+
+def fromfunction(args, dimensions):
+ return N.fromfunction(args, dimensions, dtype=int)
+
def ones(shape, typecode='l', savespace=0, dtype=None):
"""ones(shape, dtype=int) returns an array of the given
dimensions which is initialized to all ones.
Modified: trunk/numpy/oldnumeric/misc.py
===================================================================
--- trunk/numpy/oldnumeric/misc.py 2006-09-28 02:22:21 UTC (rev 3224)
+++ trunk/numpy/oldnumeric/misc.py 2006-09-28 09:56:41 UTC (rev 3225)
@@ -6,7 +6,7 @@
'choose', 'swapaxes', 'array_str',
'pi', 'math', 'concatenate', 'putmask', 'put',
'around', 'vdot', 'transpose', 'array2string', 'diagonal',
- 'searchsorted', 'fromfunction', 'copy', 'resize',
+ 'searchsorted', 'copy', 'resize',
'array_repr', 'e', 'StringIO', 'pickle',
'argsort', 'convolve', 'loads', 'cross_correlate',
'Pickler', 'dot', 'outerproduct', 'innerproduct', 'insert']
@@ -21,7 +21,7 @@
from numpy import sort, clip, rank, sign, shape, putmask, allclose, size,\
choose, swapaxes, array_str, array_repr, e, pi, put, \
- fromfunction, resize, around, concatenate, vdot, transpose, \
+ resize, around, concatenate, vdot, transpose, \
diagonal, searchsorted, argsort, convolve, dot, \
outer as outerproduct, inner as innerproduct, correlate as cross_correlate, \
place as insert
More information about the Numpy-svn
mailing list