[Numpy-discussion] Numeric to Numarray migration

Todd Miller jmiller at stsci.edu
Tue Mar 16 13:12:46 EST 2004

On Tue, 2004-03-16 at 05:59, Vineet Jain wrote:
> I'm looking to port my application to Numarray and would like some help:
> 1. How do I do the following in numarray (since from numarray import
> PyObject fails):
> 	self.startDateTimeList          = zeros(n, PyObject)

>>> import numarray.objects as obj
>>> self.startDateTimeList = obj.fromlist([0]*n)

Note that numarray.objects is an independent implementation of object
arrays which is just now coming into wider use.  I expect that there
will be gaps in functionality relative to Numeric so please ask if you
have questions.  The docstrings are currently the only documentation for
numarray's object arrays.

> 2. I have a time series array which has invalid elements. I use the
> following two functions:

Maybe someone else with more intuition about what you're trying to do
can answer this. 

If not,  get a copy of the numarray manual here:

I'd look at the functions compress(), putmask(), put(), take(), and
nonzero().  Array indexing may also come in handy.

> To get my compressed array (without the invalid elements) I use:
>             self.high = extract(prices1.high, prices1.mask)
> I then do some computations on the high in an external c library which
> populates a new array
> in the compressed format. Then I use:
>         insert(self.outIndicator,self.prices1.mask,self._outIndicator)
> This function insert from the scipy_base package was a lot faster than my
> python equivalent. But since it
> is called a lot of times the insert operation is takes a siginificant amount
> of time.
>    608400  195.333    0.000  195.333    0.000
> C:\Python23\lib\site-packages\scipy_base\function_base.py:281(insert)

If you want to use numarray and don't get the speed you want with Python
code, you might try porting the function from SciPy to numarray using
the Numeric compatibility layer.

> It represents about 25% of the application overall time. How do I do the
> same in numarray and will the performance
> be better than the above implementation. My arrays are usually greater than
> 20k in length.

Since your array sizes are large,  numarray should be fairly competitive
and depending on how the actual code works out, might even be faster. 
My guess though, is that numarray will be a little slower than Numeric
for the array sizes you're talking about and the functions you're likely
to use.


> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Todd Miller <jmiller at stsci.edu>

More information about the NumPy-Discussion mailing list