From: Magnus L. H. <ma...@he...> - 2002-12-28 22:28:52
|
Perry Greenfield <pe...@st...>: > > > There needs to be a function or method that returns the number of > > elements in an array. > > > > def Elements(array): > > """Number of elements in an array. > > > > This version is slow. > > """ > > return numarray.multiply.reduce(array.shape) len(ravel(array)) may be a faster in some cases, it seems. (Or ravel(array).shape[0], for that matter). BTW: Using the name "array" here seems just as bad as the use of "type" in numarray... Just a thought :] [snip] > > The following function is useful for downsizing arrays. I suggest that > > it should be a ufunc method. This is how I have used reduceat in Numeric. > > > > def blockreduce(array, blocksizes, ufunc): > > """Apply ufunc.reduce to blocks in an array.""" [snip] > We certainly have frequent need for a binning function (i.e., > the equivalent of a blockreduce for add). Do others see this > as a generally useful extension for all binary ufuncs? Not sure if I fully understand this -- but in my work on sequences and time series, I certainly need to do stuff like sums and averages over fixed-sized blocks of one-dimensional arrays... (Discretization.) But there are easier ways of doing that, I suppose (with reshape or indices, for example). -- Magnus Lie Hetland http://hetland.org |