[Numpy-discussion] Need help for the migration from Numeric to numpy

Bruce Southey bsouthey@gmail....
Thu Oct 14 08:53:11 CDT 2010


  On 10/14/2010 02:20 AM, Frank Thommen wrote:
> Hi,
>
> I'm trying to help a user to migrate from Numeric to numpy.  I found
> reference to alter_code1.py on
> http://numpy.scipy.org/old_array_packages.html.
>
>
> First I tried the conversion script:
>
> # python2.6 /path/to/alter_code1.py test.py
>
> and alternatively
>
> # python2.6 /path/to/alter_code1.py ./
>
> This didn't modify test.py at all.  Then I tried to convert from within
> Python:
>
> # python2.6
> Python 2.6.2 (r262:71600, Aug  5 2010, 14:21:11)
> [GCC 4.4.4] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import numpy.numarray.alter_code1 as noa
>>>> noa.convertfile("test.py")
>>>> ^D
> #
>
> This modified test.py, but only partially.  E.g. the import line was
> still untouched, meaning that it still imported Numeric instead of numpy:
>
>
> # diff ../test-original.py test.py
> 0a1,2
>> ## Automatically adapted for numpy.numarray Oct 06, 2010 by
>>
> 49c51
> <  		pyfid.byteswap()
> ---
>> 		pyfid.byteswap(True)
> 74c76
> <  		databin.byteswap()
> ---
>> 		databin.byteswap(True)
> #
>
>
> After I've changed 'import os, string, array, Numeric' to 'import os,
> string, array, numpy' I realized, that the conversion had introduced errors:
>
> # python2.6 ./test.py<command line parameters>
> Traceback (most recent call last):
>     File "./test.py", line 115, in<module>
>       combineser3D(td3,td2,td1,ser,ser1,fidnum)
>     File "./test.py", line 21, in combineser3D
>       allser1=readBrukerSer(tdall,td3,ser)
>     File "./test.py", line 51, in readBrukerSer
>       pyfid.byteswap(True)
> TypeError: byteswap() takes no arguments (1 given)
> #
>
> So either this method doesn't work (any more) or I am doing something
> wrong.  Are there other ways for a transition from Numeric to numpy?
> The numpy version we are using is 1.4.1 with Python 2.6.2 from python.org.
>
> Any help regarding this is highly appreciated.
>
>
> Thanks in advance
>
>       frank
>
>
> P.S.: I've posted almost the same request as "alter_code1.py doesn't
> convert (any more)?" on October 6.  Since I haven't received any answer
> I'm trying again with a - hopefully - more attracting subject ;-)
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
Are you converting from Numeric or numarray?
These are slightly different versions of 'alter_code1.py '.
Anyhow I would not use it because these are likely to be very out of 
date (over 2 years ago).

There used to be documentation on this but I do not see it anymore. This 
is an useful one for numarray:
http://www.stsci.edu/resources/software_hardware/numarray/numarray2numpy.pdf

A lot depends on the size of code and complexity of code - it will 
difficult to address the API changes. Essentially I just rewrote my code 
changing numarray functions to numpy functions (I really only used 
numarray). Sure my code was small and not complex but it also helped 
improve the code. From what I recall, the only things I was doing was 
changing the array declarations - especially dtypes. After those, you 
have to watch for function changes and new features.

Also I would suggest that you have a Numeric/numarray working with some 
older version of Python. This enables you to check intermediate results 
as needed.

Bruce


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20101014/66f9d26b/attachment.html 


More information about the NumPy-Discussion mailing list