Cage opened this issue on Dec 20, 2006 ยท 1232 posts
adp001 posted Sat, 15 March 2008 at 7:49 PM
Quote - ..just for completeness, here's the Numeric version of the above code:
Sorry, but whot you did has not mutch to do with using Numeric. What you do is taking a Numeric-array and transfer element by element back to python to compute results with pure Python.
What I meant with "Using Numeric isn't easy" and, most important, "consistent use of Numeric" is something like this (Numerc documentation):
Ufuncs can take output argumentsIn many computations with large sets of numbers, arrays are often used only once. For example, a computation on a large set of numbers could involve the following step
This operation as written needs to create a temporary array to store the results of the computation, and then eventually free the memory used by the original dataset array (provided there are no other references to the data it contains). It is more efficient, both in terms of memory and computation time, to do an "in-place" operation. This can be done by specifying an existing array as the place to store the result of the ufunc. In this example, one can write:
*multiply(dataset, 1.20, dataset)
....
(see orignal doc for more)
Ufuncs have special methods The reduce ufunc method If you don't know about the reduce command in Python, review section 5.1.1 of the Python Tutorial ( http://www.python.org/doc/tut/functional.html ). Briefly, reduce is most often used with two arguments, a callable object (such as a function), and a sequence. It calls the callable object with the first two elements of the sequence, then with the result of that operation and the third element, and so on, returning at the end the successive "reduction" of the specified callable object over the sequence elements. Similarly, the reduce method of ufuncs is called with a sequence as an argument, and performs the reduction of that ufunc on the sequence. As an example, adding all of the elements in a rank-1 array can be done with: