[Numpy-discussion] AUTO: Jon K Peck is out of the office (returning 05/18/2011)
I am out of the office until 05/18/2011. I am out of the office traveling Wed - Thursday, May 11-12 and Saturday-Tuesday, May 14-17. I will have limited access to email during this time, so I will be delayed in responding. Note: This is an automated response to your message "NumPy-Discussion Digest, Vol 56, Issue 25" sent on 5/12/11 11:00:02. This is the only notification you will receive while this person is away.___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ufunc 's order of execution [relevant when output overlaps with input]
> It is possible that we can make an exception for inputs and outputs > that overlap each other and pick a standard traversal. In those cases, > the order of traversal can affect the semantics, Exactly. If there is no overlap then it does not matter and can potentially be done in parallel. On the other hand if there is some standardized traversal that might allow one to write nested loops compactly. I dont really need it, but found the possibility quite intriguing. It always reads from a[i] before it writes to out[i], so it's always > consistent. > Ah I see, thanks. Should have seen through it. --sean ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ufunc 's order of execution [relevant when output overlaps with input]
On Thu, May 12, 2011 at 16:21, srean wrote: > Hi, > > is there a guarantee that ufuncs will execute left to right and in > sequential order ? By which you mean that it will traverse the elements in a 1D array left-to-right? No, this is not guaranteed. numpy reserves the right to reorder the computation for efficiency, to make the inner loop go down the axis with the smallest stride and in the direction of increasing memory addresses. We may or may not actually *do* that right now, but we reserve the right to. :-) It is possible that we can make an exception for inputs and outputs that overlap each other and pick a standard traversal. In those cases, the order of traversal can affect the semantics, so it might be nice to standardize on the most expected order and guarantee that it won't change. > For instance is the following code standards compliant ? > import numpy as n a=n.arange(0,5) > array([0, 1, 2, 3, 4]) n.add(a[0:-1], a[1:], a[0:-1]) > array([1, 3, 5, 7]) > > The idea was to reuse and hence save space. The place where I write to is > not accessed again. > > I am quite surprised that the following works correctly. > n.add.accumulate(a,out=a) > > I guess it uses a buffer and rebinds `a` to that buffer at the end. No, it's using `a` as the accumulator array. It's essentially doing the following: out[0] = a[0] + 0 out[1] = a[1] + out[0] out[2] = a[2] + out[1] ... It always reads from a[i] before it writes to out[i], so it's always consistent. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] ufunc 's order of execution [relevant when output overlaps with input]
Hi, is there a guarantee that ufuncs will execute left to right and in sequential order ? For instance is the following code standards compliant ? >>> import numpy as n >>> a=n.arange(0,5) array([0, 1, 2, 3, 4]) >>> n.add(a[0:-1], a[1:], a[0:-1]) array([1, 3, 5, 7]) The idea was to reuse and hence save space. The place where I write to is not accessed again. I am quite surprised that the following works correctly. >>>n.add.accumulate(a,out=a) I guess it uses a buffer and rebinds `a` to that buffer at the end. It is also faster than >>> n.add(a[0:-1], a[1:], a[1:]) --sean ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] RHE 4 and test failure with complex numbers (tickets: 1323, 1324 and 1325)
Hi, I think tickets 1323, 1324 and 1325 have a common source of error and, thus, are duplicates. http://projects.scipy.org/numpy/ticket/1323 http://projects.scipy.org/numpy/ticket/1324 http://projects.scipy.org/numpy/ticket/1325 These tickets could be closed just because Red Hat Enterprise Linux (RHE) 4 has been replaced by RHE 5 (first released 2007-03-14), which in turn is being replaced by RHE 6 (2010-11-10). I could not replicate this with numpy version 1.5.0 and 1.5.1 with Python 2.5.5 build with GCC 4.5.1 20100924 (Red Hat 4.5.1-4). As indicated by ticket 1325, this might be the gcc version used since RHE 4 used GCC 3.4 (RHE 5 is GCC 4.1 and RHE 6 is GCC 4.4 - http://www.redhat.com/rhel/compare/). The compiler versions used to build Python and numpy are needed unless someone can replicate these failures using either RHE 4 or older gcc version with the current numpy release. Bruce ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] f2py complications
On Thu, May 12, 2011 at 4:14 PM, Jose Gomez-Dans wrote: > Hi, > > We have some fortran code that we'd like to wrap using f2py. The code > consists of a library that we compile into an .so file, and a file that > wraps that library, which is then wrapped by f2py to provide a clean > interface to the library. The process thus includes two steps: > 1.- Use a makefile to compile the library > 2.- Use f2py to create the python bindings from a fortran file, and link > dynamically to the library created in the previous step. > > Now, I don't see why just a call to f2py shouldn't suffice (we don't really > need to have an .so lying around, and it implies that we have to set eg > $LD_LIBRARY_PATH to search for it). > It would be sufficient to just call f2py once. > I thought about using a pyf file for this, and use the only :: option: > $ f2py -h my_model.pyf -m my_model my_wrapper.f90 only: func1 func2 func3 > : all_my_other_files.f even_more_files.f90 > The above command (with using -h option) will just create the my_model.pyf file, no extra magic here, > $ f2py -c -m my_model --f90flags="-fdefault-real-8 -O3 -march=native > -m32" --f90exec=/usr/bin/gfortran --f77exec=/usr/bin/gfortran --opt=-O3 > my_model.pyf > > You need to include all .f and .f90 files to the f2py command and -m has no effect when .pyf is specified: f2py -c --f90flags="-fdefault-real-8 -O3 -march=native -m32" --f90exec=/usr/bin/gfortran --f77exec=/usr/bin/gfortran --opt=-O3 my_model.pyf all_my_other_files.f even_more_files.f90 This command (with .pyf file in command line) reads only the my_model.pyf file and creates wrapper code. It does not scan any Fortran files but only compiles them (with -c in command line) and links to the extension module. In fact, IIRC, the two above command lines can be joined to one: f2py -m my_model my_wrapper.f90 only: func1 func2 func3 : all_my_other_files.f even_more_files.f90 --f90flags="-fdefault-real-8 -O3 -march=native -m32" --f90exec=/usr/bin/gfortran --f77exec=/usr/bin/gfortran --opt=-O3 > This however, doesn't seem to work, with python complaining about missing > things. If I put all my *.f and *f90 files after the my_model.pyf (which > doesn't seem to have them in the file), I get undefined symbol errors when > importing the .so in python. > > Are you sure that you specified all needed Fortran files in the f2py command line? Where are these symbols defined that are reported to be undefined? Additionally, it would be great to have this compilation in a > distutils-friendly package, but how do you specify all these compiler flags? > > It is possible. See numpy/distutils/tests for examples. To use gfortran, run python setup.py build --fcompiler=gnu95 HTH, Pearu ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] f2py complications
Hi, We have some fortran code that we'd like to wrap using f2py. The code consists of a library that we compile into an .so file, and a file that wraps that library, which is then wrapped by f2py to provide a clean interface to the library. The process thus includes two steps: 1.- Use a makefile to compile the library 2.- Use f2py to create the python bindings from a fortran file, and link dynamically to the library created in the previous step. Now, I don't see why just a call to f2py shouldn't suffice (we don't really need to have an .so lying around, and it implies that we have to set eg $LD_LIBRARY_PATH to search for it). I thought about using a pyf file for this, and use the only :: option: $ f2py -h my_model.pyf -m my_model my_wrapper.f90 only: func1 func2 func3 : all_my_other_files.f even_more_files.f90 $ f2py -c -m my_model --f90flags="-fdefault-real-8 -O3 -march=native -m32" --f90exec=/usr/bin/gfortran --f77exec=/usr/bin/gfortran --opt=-O3 my_model.pyf This however, doesn't seem to work, with python complaining about missing things. If I put all my *.f and *f90 files after the my_model.pyf (which doesn't seem to have them in the file), I get undefined symbol errors when importing the .so in python. Additionally, it would be great to have this compilation in a distutils-friendly package, but how do you specify all these compiler flags? Thanks! Jose ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem with Numpy and array
Merci beaucoup beaucoup!! 2011/5/12 Éric Depagne > Le jeudi 12 mai 2011 12:21:46, Claudia Chan Yone a écrit : > > Hi, > > > > I have a problem with the Numpy module, but I think it is a very basic > > issue for many of you... > > I have a file with numerical data (2 columns, and 5 lignes) as : > > 1 2 > > 3 4 > > ... ... > > > > And I woulid like to convert it in a matrix as : > > [[1,2] > > [3,4] > > ...] > > > > My python script is : > > > > fic=open('file.txt','r') > > ligne=fic.readlines() > > fic.close() > > > > m=numpy.array(ligne) > > > > and I get : > > ['1,2\n' '3,4'] > > > > So I cannot call m[0][0]... > > > > Even if I modify my text file with : > > [[1,2], > > [3,4] > > ...] > > > > I get : > > > > ['[[1,2],[3,4]]'] and I cannot call m[0][0]. > > > > Thank you very much for your help, > > > > > > Clo > numpy.loadtxt() is probably what you need here. > > hth. > > Éric. > -- > Un clavier azerty en vaut deux > -- > Éric Depagnee...@depagne.org > ___ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem with Numpy and array
Le jeudi 12 mai 2011 12:21:46, Claudia Chan Yone a écrit : > Hi, > > I have a problem with the Numpy module, but I think it is a very basic > issue for many of you... > I have a file with numerical data (2 columns, and 5 lignes) as : > 1 2 > 3 4 > ... ... > > And I woulid like to convert it in a matrix as : > [[1,2] > [3,4] > ...] > > My python script is : > > fic=open('file.txt','r') > ligne=fic.readlines() > fic.close() > > m=numpy.array(ligne) > > and I get : > ['1,2\n' '3,4'] > > So I cannot call m[0][0]... > > Even if I modify my text file with : > [[1,2], > [3,4] > ...] > > I get : > > ['[[1,2],[3,4]]'] and I cannot call m[0][0]. > > Thank you very much for your help, > > > Clo numpy.loadtxt() is probably what you need here. hth. Éric. -- Un clavier azerty en vaut deux -- Éric Depagnee...@depagne.org ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem with Numpy and array
Sorry you don't have to transpose the matrix... Youngung Jeong On Thu, May 12, 2011 at 7:30 PM, Youngung Jeong wrote: > Hello, > > Use np.loadtxt > > >>> a = np.loadtxt(filename) ##in case no rows to skip. > >>> a = a.transpose() ##in your case, I guess you should > transpose it.. > > > > Youngung Jeong > > > > > On Thu, May 12, 2011 at 7:21 PM, Claudia Chan Yone < > chanyone.clau...@gmail.com> wrote: > >> Hi, >> >> I have a problem with the Numpy module, but I think it is a very basic >> issue >> for many of you... >> I have a file with numerical data (2 columns, and 5 lignes) as : >> 1 2 >> 3 4 >> ... ... >> >> And I woulid like to convert it in a matrix as : >> [[1,2] >> [3,4] >> ...] >> >> My python script is : >> >> fic=open('file.txt','r') >> ligne=fic.readlines() >> fic.close() >> >> m=numpy.array(ligne) >> >> and I get : >> ['1,2\n' '3,4'] >> >> So I cannot call m[0][0]... >> >> Even if I modify my text file with : >> [[1,2], >> [3,4] >> ...] >> >> I get : >> >> ['[[1,2],[3,4]]'] and I cannot call m[0][0]. >> >> Thank you very much for your help, >> >> >> Clo >> >> ___ >> NumPy-Discussion mailing list >> NumPy-Discussion@scipy.org >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> > ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem with Numpy and array
Hello, Use np.loadtxt >>> a = np.loadtxt(filename) ##in case no rows to skip. >>> a = a.transpose() ##in your case, I guess you should transpose it.. Youngung Jeong On Thu, May 12, 2011 at 7:21 PM, Claudia Chan Yone < chanyone.clau...@gmail.com> wrote: > Hi, > > I have a problem with the Numpy module, but I think it is a very basic > issue > for many of you... > I have a file with numerical data (2 columns, and 5 lignes) as : > 1 2 > 3 4 > ... ... > > And I woulid like to convert it in a matrix as : > [[1,2] > [3,4] > ...] > > My python script is : > > fic=open('file.txt','r') > ligne=fic.readlines() > fic.close() > > m=numpy.array(ligne) > > and I get : > ['1,2\n' '3,4'] > > So I cannot call m[0][0]... > > Even if I modify my text file with : > [[1,2], > [3,4] > ...] > > I get : > > ['[[1,2],[3,4]]'] and I cannot call m[0][0]. > > Thank you very much for your help, > > > Clo > > ___ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem with Numpy and array
On Thu, May 12, 2011 at 12:21:46PM +0200, Claudia Chan Yone wrote: > Hi, > > I have a problem with the Numpy module, but I think it is a very basic issue > for many of you... > I have a file with numerical data (2 columns, and 5 lignes) as : > 1 2 > 3 4 > ... ... > > And I woulid like to convert it in a matrix as : > [[1,2] > [3,4] > ...] > > My python script is : > > fic=open('file.txt','r') > ligne=fic.readlines() > fic.close() Try using the loadtxt function in numpy >>> m = numpy.loadtxt('file.txt') array([[ 1., 2.], [ 3., 4.]]) Miguel ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Problem with Numpy and array
Hi, I have a problem with the Numpy module, but I think it is a very basic issue for many of you... I have a file with numerical data (2 columns, and 5 lignes) as : 1 2 3 4 ... ... And I woulid like to convert it in a matrix as : [[1,2] [3,4] ...] My python script is : fic=open('file.txt','r') ligne=fic.readlines() fic.close() m=numpy.array(ligne) and I get : ['1,2\n' '3,4'] So I cannot call m[0][0]... Even if I modify my text file with : [[1,2], [3,4] ...] I get : ['[[1,2],[3,4]]'] and I cannot call m[0][0]. Thank you very much for your help, Clo ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion