Re: [Numpy-discussion] speeding up the following expression
Hi Warren, On Sat, Nov 12, 2011 at 9:31 AM, Warren Weckesser warren.weckes...@enthought.com wrote: On Sat, Nov 12, 2011 at 6:43 AM, josef.p...@gmail.com wrote: On Sat, Nov 12, 2011 at 3:36 AM, Geoffrey Zhu zyzhu2...@gmail.com wrote: Hi, I am playing with multiple ways to speed up the following expression (it is in the inner loop): C[1:(M - 1)]=(a * C[2:] + b * C[1:(M-1)] + c * C[:(M-2)]) where C is an array of about 200-300 elements, M=len(C), a, b, c are scalars. I played with numexpr, but it was way slower than directly using numpy. It would be nice if I could create a Mx3 matrix without copying memory and so I can use dot() to calculate the whole thing. Can anyone help with giving some advices to make this faster? looks like a np.convolve(C, [a,b,c]) to me except for the boundary conditions. As Josef pointed out, this is a convolution. There are (at least) three convolution functions in numpy+scipy that you could use: numpy.convolve, scipy.signal.convolve, and scipy.ndimage.convolve1d. Of these, scipy.ndimage.convolve1d is the fastest. However, it doesn't beat the simple expression a*x[2:] + b*x[1:-1] + c*x[:-2] Your idea of forming a matrix without copying memory can be done using stride tricks, and for arrays of the size you are interested in, it computes the result faster than the simple expression (see below). Another fast alternative is to use one of the inline code generators. This example is a easy to implement with scipy.weave.blitz, and it gives a big speedup. Here's a test script: #- convolve1dtest.py - import numpy as np from numpy.lib.stride_tricks import as_strided from scipy.ndimage import convolve1d from scipy.weave import blitz # weighting coefficients a = -0.5 b = 1.0 c = -0.25 w = np.array((a,b,c)) # Reversed w: rw = w[::-1] # Length of C n = 250 # The original version of the calculation: # Some dummy data C = np.arange(float(n)) C[1:-1] = a * C[2:] + b * C[1:-1] + c * C[:-2] # Save for comparison. C0 = C.copy() # Do it again using a matrix multiplication. C = np.arange(float(n)) # The virtual matrix view of C. V = as_strided(C, shape=(C.size-2, 3), strides=(C.strides[0], C.strides[0])) C[1:-1] = np.dot(V, rw) C1 = C.copy() # Again, with convolve1d this time. C = np.arange(float(n)) C[1:-1] = convolve1d(C, w)[1:-1] C2 = C.copy() # scipy.weave.blitz C = np.arange(float(n)) # Must work with a copy, D, in the formula, because blitz does not use # a temporary variable. D = C.copy() expr = C[1:-1] = a * D[2:] + b * D[1:-1] + c * D[:-2] blitz(expr, check_size=0) C3 = C.copy() # Verify that all the methods give the same result. print np.all(C0 == C1) print np.all(C0 == C2) print np.all(C0 == C3) #- And here's a snippet from an ipython session: In [51]: run convolve1dtest.py True True True In [52]: %timeit C[1:-1] = a * C[2:] + b * C[1:-1] + c * C[:-2] 10 loops, best of 3: 16.5 us per loop In [53]: %timeit C[1:-1] = np.dot(V, rw) 10 loops, best of 3: 9.84 us per loop In [54]: %timeit C[1:-1] = convolve1d(C, w)[1:-1] 10 loops, best of 3: 18.7 us per loop In [55]: %timeit D = C.copy(); blitz(expr, check_size=0) 10 loops, best of 3: 4.91 us per loop scipy.weave.blitz is fastest (but note that blitz has already been called once, so the time shown does not include the compilation required in the first call). You could also try scipy.weave.inline, cython.inline, or np_inline (http://pages.cs.wisc.edu/~johnl/np_inline/). Also note that C[-1:1] = np.dot(V, rw) is faster than either the simple expression or convolve1d. However, if you also have to set up V inside your inner loop, the speed gain will be lost. The relative speeds also depend on the size of C. For large C, the simple expression is faster than the matrix multiplication by V (but blitz is still faster). In the following, I have changed n to 2500 before running convolve1dtest.py: In [56]: run convolve1dtest.py True True True In [57]: %timeit C[1:-1] = a * C[2:] + b * C[1:-1] + c * C[:-2] 1 loops, best of 3: 29.5 us per loop In [58]: %timeit C[1:-1] = np.dot(V, rw) 1 loops, best of 3: 56.4 us per loop In [59]: %timeit C[1:-1] = convolve1d(C, w)[1:-1] 1 loops, best of 3: 37.3 us per loop In [60]: %timeit D = C.copy(); blitz(expr, check_size=0) 10 loops, best of 3: 10.3 us per loop blitz wins, the simple numpy expression is a distant second, and now the matrix multiplication is slowest. I hope that helps--I know I learned quite a bit. :) Warren Thanks for the very helpful response. Fortunately I don't have to set up the matrix every time as I can work on the same C over and over again inside the loop. It's counterintuitive to see that the performance of dot() degrades as n goes up. If I didn't see the results, I would have guessed otherwise. Thanks again! Geoffrey ___ NumPy
Re: [Numpy-discussion] OT: A Way to Approximate and Compress a 3D Surface
Hi Bob, Anne, and everyone, On Nov 21, 2007 1:41 PM, Bob Lewis [EMAIL PROTECTED] wrote: On 11/20/07, Anne Archibald posted: Subject: Re: [Numpy-discussion] OT: A Way to Approximate and Compress a 3D Surface From: Anne Archibald [EMAIL PROTECTED] Date: Tue, 20 Nov 2007 17:13:31 -0500 To: Discussion of Numerical Python numpy-discussion@scipy.org To: Discussion of Numerical Python numpy-discussion@scipy.org On 20/11/2007, Geoffrey Zhu [EMAIL PROTECTED] wrote: I have N tabulated data points { (x_i, y_i, z_i) } that describes a 3D surface. The surface is pretty smooth. However, the number of data points is too large to be stored and manipulated efficiently. To make it easier to deal with, I am looking for an easy method to compress and approximate the data. Maybe the approximation can be described by far fewer number of coefficients. If you can give me some hints about possible numpy or non-numpy solutions or let me know where is better to ask this kind of question, I would really appreciate it. This is an important task in computer graphics, in particular, in the field of multiresolution modelling. If you look up surface simplification you'll find many references to articles. I don't know of a library offhand that does it, let alone one that is accessible from python, but you could try looking at a toolkit that does isosurface visualization - these are surfaces that can often be simplified enormously. In particular it looks like VTK might be able to do what you want. Anne Archibald is correct that surface simplification may ultimately be of great help. Other place to look besides VTK are GTS, the GNU Triangulated Surface library, and CGAL, the Computational Geometry Algorithms Library, which has a Python binding. It occurs to me, though, that we should first verify that you do indeed have a surface in the first place. All you tell us is that you have a set of N points in 3-space. Are they connected? That is, does each point have well-defined neighbors? If so, do these vertices and connections form a mesh that defines a surface? - Bob Lewis ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion First I'd like to thank everyone for helping me on this. It does look like surface simplification will greatly help my problem. Yes, I indeed have a surface and the points are connected. In fact, I have a function z=f(x,y). Except at certain points, it is continuous and smooth. It is very computationally intensive to calculate f(x,y), so I have to calculate certain points {(x_i,y_i_,z_i)} and store the data in a database. However, I have thousands of such functions and therefore a lot of points to deal with and that makes manipulating and storing them difficult and slow. One thing about triangulation I haven't figured out is how to add multiple such functions together. So if I have a set of triangles that represent f1(x,y) and another set of triangles that represent f2(x,y), is there any quick way to get f1(x,y)+f2(x,y) from the triangulation results of the parts? Thanks again for all your help, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] OT: A Way to Approximate and Compress a 3D Surface
Hi Everyone, This is off topic for this mailing list but I don't know where else to ask. I have N tabulated data points { (x_i, y_i, z_i) } that describes a 3D surface. The surface is pretty smooth. However, the number of data points is too large to be stored and manipulated efficiently. To make it easier to deal with, I am looking for an easy method to compress and approximate the data. Maybe the approximation can be described by far fewer number of coefficients. If you can give me some hints about possible numpy or non-numpy solutions or let me know where is better to ask this kind of question, I would really appreciate it. Many thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem with numpy.linalg.eig?
On Nov 13, 2007 2:37 AM, David Cournapeau [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: Yes, with the MSI I can always reproduce the problem with numpy.test(). It always hangs.With the egg it does not hang. Pointer problems are usually random, but not random if we are using the same binaries in EGG and MSI and variables are always initialized to certain value. Ok, could you try this: http://www.ar.media.kyoto-u.ac.jp/members/david/archives/numpy-1.0.4.win32-py2.5.msi I built it with mingwin, and with NETLIB BLAS/LAPACK. This is just for testing, do not use it for anything else. David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion I just tried. Your new MSI does not hang on numpy.test() and the OP's test case, and it seems faster. The EGG version does not hang on numpy.test() but does on OP's test. The original MSI version hangs on numpy.test() if I open IDLE and type import numpy numpy.test() If I try the OP's test first, once it hang on from numpy.linalg import eig and the other time it ran successfully. After it ran successfully, it ran numpy.test() successfully, too. As you said, it is random. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem with numpy.linalg.eig?
On Nov 12, 2007 12:37 PM, Keith Goodman [EMAIL PROTECTED] wrote: On Nov 12, 2007 10:10 AM, Peter Creasey [EMAIL PROTECTED] wrote: The following code calling numpy v1.0.4 fails to terminate on my machine, which was not the case with v1.0.3.1 from numpy import arange, float64 from numpy.linalg import eig a = arange(13*13, dtype = float64) a.shape = (13,13) a = a%17 eig(a) It sounds like the same problem that was reported in this thread: http://thread.gmane.org/gmane.comp.python.numeric.general/17456/focus=17465 A friend of mine says the windows binary of 1.0.4 also hangs on eigh and lstsq (so linalg in general). I don't have that problem on 1.0.5 compiled on GNU/Linux. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion The code hangs on my machine too. In the thread you mentioned above, I wrote that using the EGG instead of MSI appears to fix the numpy.test() problem, but maybe it just somehow hides it. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem with numpy.linalg.eig?
On Nov 12, 2007 10:26 PM, David Cournapeau [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: On Nov 12, 2007 12:37 PM, Keith Goodman [EMAIL PROTECTED] wrote: On Nov 12, 2007 10:10 AM, Peter Creasey [EMAIL PROTECTED] wrote: The following code calling numpy v1.0.4 fails to terminate on my machine, which was not the case with v1.0.3.1 from numpy import arange, float64 from numpy.linalg import eig a = arange(13*13, dtype = float64) a.shape = (13,13) a = a%17 eig(a) It sounds like the same problem that was reported in this thread: http://thread.gmane.org/gmane.comp.python.numeric.general/17456/focus=17465 The code hangs on my machine too. In the thread you mentioned above, I wrote that using the EGG instead of MSI appears to fix the numpy.test() problem, but maybe it just somehow hides it. When you use the MSI, can you always reproduce the problem ? As I said previously, it is hard to know for sure without being able to reproduce the bug on our own workstation, but if this is a problem between fortran and C argument passing, then the result can be pretty random since the problem reduced to a pointer pointing at a wrong address (crash, wrong value, etc...). cheers, David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion Yes, with the MSI I can always reproduce the problem with numpy.test(). It always hangs.With the egg it does not hang. Pointer problems are usually random, but not random if we are using the same binaries in EGG and MSI and variables are always initialized to certain value. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy 1.04 numpy.test() hang
On Nov 8, 2007 10:06 PM, David Cournapeau [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: On Nov 8, 2007 12:12 PM, Robert Kern [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: Good morning. I just installed the Windows binary of numpy 1.04. When I ran numpy.test() in IDLE (the Python shell that comes with Python), the program hang (or at least is running for half an hour). I am using Windows XP, duel core intel CPU. Does anyone know what is going on? No. Run numpy.test(verbosity=2) so it will print out each test name before running the test. Then we might have some idea about where the hang is coming from. -- 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://projects.scipy.org/mailman/listinfo/numpy-discussion Thanks for the hint, Robert. It hangs on check_cdouble (numpy.tests.test_linalg.test_det). Also testip_not_allclose() had three warnings. I guess that's probably okay. testip_not_allclose (numpy.core.tests.test_numeric.test_allclose_inf) ... Warning: invalid value encountered in absolute Warning: invalid value encountered in absolute Warning: invalid value encountered in less_equal ok Are you on x86-64, too ? Which BLAS are you using ? This smells like a C/Fortran problem (because it happens with complex values only). cheers, David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion Hi David, Although the processor is Intel Duo Core E6700, which supports x86-64, I am only using 32-bit Windows XP. I am not using my own BLAS. I am simply using the pre-compiled binary. I installed 1.04 over the old 1.031. I don't know if it is caused by some files that are left behind. Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy 1.04 numpy.test() hang
On Nov 9, 2007 10:14 AM, Geoffrey Zhu [EMAIL PROTECTED] wrote: On Nov 8, 2007 10:06 PM, David Cournapeau [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: On Nov 8, 2007 12:12 PM, Robert Kern [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: Good morning. I just installed the Windows binary of numpy 1.04. When I ran numpy.test() in IDLE (the Python shell that comes with Python), the program hang (or at least is running for half an hour). I am using Windows XP, duel core intel CPU. Does anyone know what is going on? No. Run numpy.test(verbosity=2) so it will print out each test name before running the test. Then we might have some idea about where the hang is coming from. -- 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://projects.scipy.org/mailman/listinfo/numpy-discussion Thanks for the hint, Robert. It hangs on check_cdouble (numpy.tests.test_linalg.test_det). Also testip_not_allclose() had three warnings. I guess that's probably okay. testip_not_allclose (numpy.core.tests.test_numeric.test_allclose_inf) ... Warning: invalid value encountered in absolute Warning: invalid value encountered in absolute Warning: invalid value encountered in less_equal ok Are you on x86-64, too ? Which BLAS are you using ? This smells like a C/Fortran problem (because it happens with complex values only). cheers, David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion Hi David, Although the processor is Intel Duo Core E6700, which supports x86-64, I am only using 32-bit Windows XP. I am not using my own BLAS. I am simply using the pre-compiled binary. I installed 1.04 over the old 1.031. I don't know if it is caused by some files that are left behind. Thanks, Geoffrey Okay. I verified (by looking at which DLL python.exe actually loads) that it is using _dotblas.pyd under C:\Python25\Lib\site-packages\numpy\core that came with the pre-built 1.04 binary. It is not using any left-over from 1.031. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] numpy 1.04 numpy.test() hang
Good morning. I just installed the Windows binary of numpy 1.04. When I ran numpy.test() in IDLE (the Python shell that comes with Python), the program hang (or at least is running for half an hour). I am using Windows XP, duel core intel CPU. Does anyone know what is going on? Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy 1.04 numpy.test() hang
On Nov 8, 2007 12:12 PM, Robert Kern [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: Good morning. I just installed the Windows binary of numpy 1.04. When I ran numpy.test() in IDLE (the Python shell that comes with Python), the program hang (or at least is running for half an hour). I am using Windows XP, duel core intel CPU. Does anyone know what is going on? No. Run numpy.test(verbosity=2) so it will print out each test name before running the test. Then we might have some idea about where the hang is coming from. -- 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://projects.scipy.org/mailman/listinfo/numpy-discussion Thanks for the hint, Robert. It hangs on check_cdouble (numpy.tests.test_linalg.test_det). Also testip_not_allclose() had three warnings. I guess that's probably okay. testip_not_allclose (numpy.core.tests.test_numeric.test_allclose_inf) ... Warning: invalid value encountered in absolute Warning: invalid value encountered in absolute Warning: invalid value encountered in less_equal ok Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Bug in piecewise?
Hi All, If I execute the following code, I find that function f() sometimes is called with an empty array. I am not sure why this is necessary. Is this a bug? def f(x): return x**2 return numpy.piecewise(u, abs(u)1, [f, 0]) Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Sum of the product of three or more arrays
On 10/18/07, Robert Kern [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: Hi All, Given three vectors of the same lengths, X, Y, and Z, I am looking for an efficient way to calculate the following: sum(x[i]*y[i]*z[i], for i=1..n ) (x*y*z).sum() -- 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://projects.scipy.org/mailman/listinfo/numpy-discussion Thanks Robert. (x*y*z).sum() is probably faster than sum(x*y*z). ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Sum of the product of three or more arrays
I think I figured out: sum(X*Y*Z). Never mind. On 10/18/07, Geoffrey Zhu [EMAIL PROTECTED] wrote: Hi All, Given three vectors of the same lengths, X, Y, and Z, I am looking for an efficient way to calculate the following: sum(x[i]*y[i]*z[i], for i=1..n ) I am not sure if there is a vectorized way to do this. Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Sum of the product of three or more arrays
Hi All, Given three vectors of the same lengths, X, Y, and Z, I am looking for an efficient way to calculate the following: sum(x[i]*y[i]*z[i], for i=1..n ) I am not sure if there is a vectorized way to do this. Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Extended Outer Product
On 8/21/07, Timothy Hochberg [EMAIL PROTECTED] wrote: On 8/21/07, Charles R Harris [EMAIL PROTECTED] wrote: On 8/20/07, Geoffrey Zhu [EMAIL PROTECTED] wrote: Hi Everyone, I am wondering if there is an extended outer product. Take the example in Guide to Numpy. Instead of doing an multiplication, I want to call a custom function for each pair. print outer([1,2,3],[10,100,1000]) [[ 10 100 1000] [ 20 200 2000] [ 30 300 3000]] So I want: [ [f(1,10), f(1,100), f(1,1000)], [f(2,10), f(2, 100), f(2, 1000)], [f(3,10), f(3, 100), f(3,1000)] ] Maybe something like In [15]: f = lambda x,y : x*sin(y) In [16]: a = array([[f(i,j) for i in range(3)] for j in range(3)]) In [17]: a Out[17]: array([[ 0., 0., 0.], [ 0., 0.84147098, 1.68294197], [ 0., 0.90929743, 1.81859485]]) I don't know if nested list comprehensions are faster than two nested loops, but at least they avoid array indexing. This is just a general comment on recent threads of this type and not directed specifically at Chuck or anyone else. IMO, the emphasis on avoiding FOR loops at all costs is misplaced. It is often more memory friendly and thus faster to vectorize only the inner loop and leave outer loops alone. Everything varies with the specific case of course, but trying to avoid FOR loops on principle is not a good strategy. I agree. My original post asked for solutions without using two nested for loops because I already know the two for loop solution. Besides, I was hoping that some version of 'outer' will take in a function reference and call the function instead of doing multiplifcation. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] numpy.array does not take generators
Hi All, I want to construct a numpy array based on Python objects. In the below code, opts is a list of tuples. For example, opts=[ ('C', 100, 3, 'A'), ('K', 200, 5.4, 'B')] If I use a generator like the following: K=numpy.array(o[2]/1000.0 for o in opts) It does not work. I have to use: numpy.array([o[2]/1000.0 for o in opts]) Is this behavior intended? By the way, it is quite inefficient to create numpy array this way, because I have to create a regular python first, and then construct a numpy array. But I do not want to store everything in vector form initially, as it is more natural to store them in objects, and easier to use when organizing the data. Does anyone know any better way? Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] How to implement a 'pivot table?'
Hi Timothy, On 7/31/07, Timothy Hochberg [EMAIL PROTECTED] wrote: [SNIP] The 'brute-force' way is basically what you suggested -- looping through all the records and building a two-way hash-table of the data. The problem of the brute-force' approach is that it is not taking advantage of facilities of numpy and can be slow in speed. If only there is some built-in mechanism in numpy to handle this. I'm curious; have you tried this and found it slow, or is this a hunch based on the reputed slowness of Python? Algorithmically, you can't do much better: the dictionary and set operations are O(1), so the whole operation is O(N), and you won't do any better than that, order wise. What your left with is trying to reduce constant factors. I agree that algorithmically you can't do much better. It is basically a C vs Python thing. One advantage of numpy is that you can do vectorized operations at the speed of C. With this algorithm, we have to process the data element by element and the speed advantage of numpy is lost. Since data has to be stored in python sets and maps, I imagine the storage advantage is also lost. I was in fact looking for some implemention of this algorithm in numpy (and so C) that does exactly this, or some implementation of this algorithm that can leverage the fast numpy routines to do this. I haven't tried it with the real data load yet. I know the number of records will be huge and it is just a hunch that it will be slow. There are various ways one might go about reducing constant factors, but they depend on the details of the problem. For example, if the dates are dense and you are going to parse them anyway, you could replace the hash with table that you index into with the date as an integer. I'm not sure that you are going to do a lot better than the brute force algorithm in the generic force case though. Unfortunately it has to be something generic. Thanks a lot for your help. Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] How to implement a 'pivot table?'
Hi Timothy, On 7/30/07, Timothy Hochberg [EMAIL PROTECTED] wrote: On 7/30/07, Geoffrey Zhu [EMAIL PROTECTED] wrote: Hi Everyone, I am wondering what is the best (and fast) way to build a pivot table aside from the 'brute force way?' What's the brute force way? It's easier to offer an improved suggestion if we know what we're trying to beat. I want to transform an numpy array into a pivot table. For example, if I have a numpy array like below: Region Date # of Units ------ East1/1 10 East1/1 20 East1/2 30 West 1/1 40 West 1/2 50 West 1/2 60 I want to transform this into the following table, where f() is a given aggregate function: Date Region 1/1 1/2 -- East f(10,20) f(30) Westf(40) f(50,60) I can regroup them into 'sets' and do it the brute force way, but that is kind of slow to execute. Does anyone know a better way? I would use a python to dictionary to assemble lists of values. I would key off (region/date) tuples. In outline: map = {} dates = set() regions = set() for (region, date, units) in data: dates.add(date) regions.add(regions) key = (region, date) if key not in map: map[key] = [] map[key].append(data) Once you have map, regions and dates, you can trivially make a table as above. The details will depend on what format you want the table to have, but it should be easy to do. Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion -- . __ . |-\ . . [EMAIL PROTECTED] ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion The 'brute-force' way is basically what you suggested -- looping through all the records and building a two-way hash-table of the data. The problem of the brute-force' approach is that it is not taking advantage of facilities of numpy and can be slow in speed. If only there is some built-in mechanism in numpy to handle this. The other thing I am not sure is in your map object above, do I append the row number to the numpy array or do I append the row object (such as data[r])? Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Build external C functions that take numpy arrays as parameters and return numpy arrays
Hi Sebastian, Oooh - I see - there is the date: July 24 ... [ another email just came in is from 7/18 ...] That's quite interesting. I have never seen such a delay before Was some computer sitting on them being turnted off for 10 days ? ;-) -Sebastian. Not knowing that the mailing list and the google group Numpy Discussion are one and the same, originally I posted this question through Google Groups. Until now it never showed up in the group. I thought it was lost and made another post to the mailing list. In fact with the help of people on this mailing list and some trial and error, I have already built an extended moudle that does exactly that. Thanks for your help. Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Build external C functions that take numpy arrays as parameters and return numpy arrays
On 7/29/07, Lou Pecora [EMAIL PROTECTED] wrote: I wrote a basic article on C extensions using NumPy arrays on the SciPy.org site. See: Cookbook/C_Extensions/NumPy at http://www.scipy.org/Cookbook/C_Extensions/NumPy_arrays?highlight=%28%28%28-%2A%29%28%5Cr%29%3F%5Cn%29%28.%2A%29CategoryCookbook%5Cb%29 It's very basic, but should get you started. Note that once you get the patterns down for NumPy then other extensions are mostly the same pattern over and over. -- Lou Pecora That was the 'template' I was using. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] C-extension -- how do I accept a vector of both type double and type int?
On 7/26/07, Robert Kern [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: How do I handle this situation? Is there any way to access any data type that can be converted into a double? I usually use PyArray_FROM_OTF(). That handles the usual cases. It's pretty much like starting off a pure Python function with asarray(x, dtype=whatever). That is going to make a copy of the memory every time and might slow down things a lot? Not if you pass it an array with the requested properties. Neat. Do you know if PyArray_FROM_OTF() increments the reference count of the returned object? The documentation does not say. My guess is yes. Yes. Hi Robert, This is probably off the topic. Do you know such a function for regular python objects? For example, I know a PyObject is a number, but I don't know the exact type. Is there any quick way to convert it to a C double type? Thanks, cg ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] C-extension -- how do I accept a vector of both type double and type int?
How do I handle this situation? Is there any way to access any data type that can be converted into a double? I usually use PyArray_FROM_OTF(). That handles the usual cases. It's pretty much like starting off a pure Python function with asarray(x, dtype=whatever). That is going to make a copy of the memory every time and might slow down things a lot? Not if you pass it an array with the requested properties. Neat. Do you know if PyArray_FROM_OTF() increments the reference count of the returned object? The documentation does not say. My guess is yes. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] C-extension -- how do I accept a vector of both type double and type int?
Hi Everyone, I finally build a C extension. The one problem I found is that it is too picky about the input. For example, it accepts array([1.0,2.0,3.0]) with no problem, but when I pass in array([1,2,3]), since the dtype of the array is now int, my extension does not like it. How do I handle this situation? Is there any way to access any data type that can be converted into a double? Thanks, cg ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] C-extension -- how do I accept a vector of both type double and type int?
On 7/26/07, Robert Kern [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: Hi Everyone, I finally build a C extension. The one problem I found is that it is too picky about the input. For example, it accepts array([1.0,2.0,3.0]) with no problem, but when I pass in array([1,2,3]), since the dtype of the array is now int, my extension does not like it. Okay. Show us the code that you are using, and we can help you find a better way. How do I handle this situation? Is there any way to access any data type that can be converted into a double? I usually use PyArray_FROM_OTF(). That handles the usual cases. It's pretty much like starting off a pure Python function with asarray(x, dtype=whatever). That is going to make a copy of the memory every time and might slow down things a lot? ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Should I use numpy array?
Hi, I am writing a function that would take a list of datetime objects and a list of single letter characters (such as [A,B,C]). The number of items tend to be big and both the list and the numpy array have all the functionalities I need. Do you think I should use numpy arrays or the regular lists? Thanks, cg ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Compile extension modules with Visual Studio 2005
Hi, I am about to write a C extension module. C functions in the module will take and return numpy arrays. I found a tutorial online, but I am not sure about the following: 1. Can I compile my extension with Visual Studio 2005? My impression is that I will have to link with numpy libraries, and, if numpy was compiled with a different compiler, I might have problems. However, if numpy is a DLL, maybe there is a way that I can build a LIB file based on the DLL and link with the LIB file. Does anyone have experience in doing this? 2. I am new to writing python extensions. The tutorial is doing things by hand. Does anyone know what is the best way to do this? How about SWIG? Thanks, Geoffrey ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Compile extension modules with Visual Studio 2005
Hi Robert, On 7/24/07, Robert Kern [EMAIL PROTECTED] wrote: Geoffrey Zhu wrote: Thanks for your help. Do you know what exactly is the issue of having to use VS2003 to build extensions? If the interactions are done at DLL level, shouldn't call compilers that can generate DLLs work? Mostly it's an issue of the C runtime that is used for either compiler. C extensions need to use the same runtime as Python itself. Mostly. If it is a problem of the runtime library conflict, I can probably statically link the VS2005 runtime into my extension DLL and there would be no conflict. Do you see any problems with this plan? :-) It doesn't look like using ctypes would be an option, as my goal is to 'vectorize' some operations. You mean you need to use PyMultiIter objects for broadcasting? Yeah, that would require an extension. I haven't looked at PyMultilter objects. I am just trying to build a 'vector version' of my C function so that it can do batch calculations. For example, for a vector X, I can do for x in X: y=my_func(x) Or I can do Y=my_vector_func(X). The latter is probably much more efficient. That's why I need the extension. Thanks, Geoffrey -- 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://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Logical Selector
Hi, Well maybe it is a bug on my box (thunderbird) but the topic of the thread is -lmkl_lapack64 on i368 ??. Nothing to do with Logical Selector ;) Should I post another mail about this topic? Xavier ps : I'm just sorry for the noise if it is a bug on my side. -- Hi Xavier, I didn't know mailing lists track threads. The messages look all independent in Microsoft Outlook. So I just hit reply on your message, changed the title, and put in my message... Sorry about that. Geoffrey ___=0A= =0A= The information in this email or in any file attached=0A= hereto is intended only for the personal and confiden-=0A= tial use of the individual or entity to which it is=0A= addressed and may contain information that is propri-=0A= etary and confidential. If you are not the intended=0A= recipient of this message you are hereby notified that=0A= any review, dissemination, distribution or copying of=0A= this message is strictly prohibited. This communica-=0A= tion is for information purposes only and should not=0A= be regarded as an offer to sell or as a solicitation=0A= of an offer to buy any financial product. Email trans-=0A= mission cannot be guaranteed to be secure or error-=0A= free. P6070214 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Logical Selector
Hi Everyone, I am finding that numpy cannot operate on boolean arrays. For example, the following does not work: x=3Darray([(1,2),(2,1),(3,1),(4,1)]) x[x[:,0]x[:,1] and x[1:]1,:] It gives me an syntax error: --- Traceback (most recent call last): File pyshell#74, line 1, in module x[x[:,0]x[:,1] and x[1:]1,:] ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() --- However, this is not what I want. I want a piece-wise AND operation on the two boolean vectors. In other words, the row is selected if both are true. How do I accomplish this? Many thanks, Geoffrey P.S The disclaimer is automatically generated by the mail server. ___=0A= =0A= The information in this email or in any file attached=0A= hereto is intended only for the personal and confiden-=0A= tial use of the individual or entity to which it is=0A= addressed and may contain information that is propri-=0A= etary and confidential. If you are not the intended=0A= recipient of this message you are hereby notified that=0A= any review, dissemination, distribution or copying of=0A= this message is strictly prohibited. This communica-=0A= tion is for information purposes only and should not=0A= be regarded as an offer to sell or as a solicitation=0A= of an offer to buy any financial product. Email trans-=0A= mission cannot be guaranteed to be secure or error-=0A= free. P6070214 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Numpy and iterative procedures
In fact I am not looking for an implementation but a method to update a vector iteratively when the value of an item of the vector depend partly on the already updated items and partly depend on the old items. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nils Wagner Sent: Friday, February 16, 2007 9:19 AM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] Numpy and iterative procedures Nadav Horesh wrote: At first glance it doesn't look hard to, at least, avoid looping over i, by replacing [i] by [:-2], [i+1] by [1:-1] and [i+2] by [2:]. But I might be wrong. Can you submit the piece of code with at least the most internal loop? Nadav. I guess he is looking for an implementation of http://en.wikipedia.org/wiki/Successive_over-relaxation Nils -Original Message- From: [EMAIL PROTECTED] on behalf of Geoffrey Zhu Sent: Thu 15-Feb-07 18:32 To: Discussion of Numerical Python Cc: Subject: Re: [Numpy-discussion] Numpy and iterative procedures Thanks Chuck. I am trying to use Successive Over-relaxation to solve linear equations defined by M*v=q. There are several goals: 1. Eventually (in production) I need it to be fast. 2. I am playing with the guts of the algorithm for now, to see how it works. that means i need some control for now. 3. Even in production, there is a chance i'd like to have the ability to tinker with the algorithm. _ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Charles R Harris Sent: Thursday, February 15, 2007 10:11 AM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] Numpy and iterative procedures On 2/15/07, Geoffrey Zhu [EMAIL PROTECTED] wrote: Hi, I am new to numpy. I'd like to know if it is possible to code efficient iterative procedures with numpy. Specifically, I have the following problem. M is an N*N matrix. Q is a N*1 vector. V is an N*1 vector I am trying to find iteratively from the initial value V_0. The procedure is simply to calculate V_{n+1}[i]=3D1/M[I,i]*(q[i]- (M[i,1]*v_{n+1}[1]+M[I,2]*v_{n+1}[2]+..+M[i,i-1]*v_{n+1}[i-1]) - (M[I,i+1]*v_{n}[i+1]+M[I,i+2]*v_{n}[i+2]+..+M[I,N]*v_{n}[N])) I do not see that this is something that can esaily be vectorized, is it? I think it would be better if you stated what the actual problem is. Is it a differential equation, for instance. That way we can determine what the problem class is and what algorithms are available to solve it. Chuck ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Numpy and iterative procedures
Hi Nadav, The code is attached at the end. There is probably still bugs in there but it does not prevent me from showing the difficulity. If you look at the inner loop below, you will see that vector v is updated element by element. The new value of v[i] depends on the new value of v[i-1] and the old value of v[i+1]. Updating an element involves the new values of the already updated elements and the old values of the rest of the elements that we have yet to update. This makes vectorization difficult. for i in range(1,N-1): temp[i]=3D(1-w)*v[i]+w/D[i]*(q[i]-L[i-1]*v[i-1]-U[i]*v[i+1]) err +=3D (temp[i]-v[i])**2 v[i]=3Dtemp[i] Thanks, Geoffrey Complete code here; def sor(v, L, D, U ,q, tol, w): '''solve M*v=3Dq. return v. L, D, U are the sub-diagonal, diagonal, and super-diagonal of the matrix M. ''' err=3D999 N=3DD.shape[0] #number of elements temp=3Dempty(N) while err tol : err=3D0 temp[0]=3D(1-w)*v[0]+w/D[0]*(q[0]-U[0]*v[1]) err +=3D (temp[0]-v[0])**2 v[0]=3Dtemp[0] for i in range(1,N-1): temp[i]=3D(1-w)*v[i]+w/D[i]*(q[i]-L[i-1]*v[i-1]-U[i]*v[i+1]) err +=3D (temp[i]-v[i])**2 v[i]=3Dtemp[i] temp[N-1]=3D(1-w)*v[N-1]+w/D[N-1]*(q[N-1]-L[N-2]*v[N-2]) err +=3D (temp[N-1]-v[N-1])**2 v[N-1]=3Dtemp[N-1] return v -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nadav Horesh Sent: Friday, February 16, 2007 8:52 AM To: Discussion of Numerical Python Subject: RE: [Numpy-discussion] Numpy and iterative procedures At first glance it doesn't look hard to, at least, avoid looping over i, by replacing [i] by [:-2], [i+1] by [1:-1] and [i+2] by [2:]. But I might be wrong. Can you submit the piece of code with at least the most internal loop? Nadav. -Original Message- From: [EMAIL PROTECTED] on behalf of Geoffrey Zhu Sent: Thu 15-Feb-07 18:32 To: Discussion of Numerical Python Cc: Subject:Re: [Numpy-discussion] Numpy and iterative procedures Thanks Chuck. I am trying to use Successive Over-relaxation to solve linear equations defined by M*v=3Dq. There are several goals: 1. Eventually (in production) I need it to be fast. 2. I am playing with the guts of the algorithm for now, to see how it works. that means i need some control for now. 3. Even in production, there is a chance i'd like to have the ability to tinker with the algorithm. _ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Charles R Harris Sent: Thursday, February 15, 2007 10:11 AM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] Numpy and iterative procedures On 2/15/07, Geoffrey Zhu [EMAIL PROTECTED] wrote: Hi, I am new to numpy. I'd like to know if it is possible to code efficient iterative procedures with numpy. Specifically, I have the following problem. M is an N*N matrix. Q is a N*1 vector. V is an N*1 vector I am trying to find iteratively from the initial value V_0. The procedure is simply to calculate V_{n+1}[i]=3D3D1/M[I,i]*(q[i]- (M[i,1]*v_{n+1}[1]+M[I,2]*v_{n+1}[2]+..+M[i,i-1]*v_{n+1}[i-1]) - (M[I,i+1]*v_{n}[i+1]+M[I,i+2]*v_{n}[i+2]+..+M[I,N]*v_{n}[N])) I do not see that this is something that can esaily be vectorized, is it? I think it would be better if you stated what the actual problem is. Is it a differential equation, for instance. That way we can determine what the problem class is and what algorithms are available to solve it. Chuck ___=0A= =0A= The information in this email or in any file attached=0A= hereto is intended only for the personal and confiden-=0A= tial use of the individual or entity to which it is=0A= addressed and may contain information that is propri-=0A= etary and confidential. If you are not the intended=0A= recipient of this message you are hereby notified that=0A= any review, dissemination, distribution or copying of=0A= this message is strictly prohibited. This communica-=0A= tion is for information purposes only and should not=0A= be regarded as an offer to sell or as a solicitation=0A= of an offer to buy any financial product. Email trans-=0A= mission cannot be guaranteed to be secure or error-=0A= free. P6070214=0A= ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Numpy and iterative procedures
Hi, I am new to numpy. I'd like to know if it is possible to code efficient iterative procedures with numpy. Specifically, I have the following problem. M is an N*N matrix. Q is a N*1 vector. V is an N*1 vector I am trying to find iteratively from the initial value V_0. The procedure is simply to calculate V_{n+1}[i]=3D1/M[I,i]*(q[i]- (M[i,1]*v_{n+1}[1]+M[I,2]*v_{n+1}[2]+..+M[i,i-1]*v_{n+1}[i-1]) - (M[I,i+1]*v_{n}[i+1]+M[I,i+2]*v_{n}[i+2]+..+M[I,N]*v_{n}[N])) I do not see that this is something that can esaily be vectorized, is it? Thanks, Geoffrey ___=0A= =0A= The information in this email or in any file attached=0A= hereto is intended only for the personal and confiden-=0A= tial use of the individual or entity to which it is=0A= addressed and may contain information that is propri-=0A= etary and confidential. If you are not the intended=0A= recipient of this message you are hereby notified that=0A= any review, dissemination, distribution or copying of=0A= this message is strictly prohibited. This communica-=0A= tion is for information purposes only and should not=0A= be regarded as an offer to sell or as a solicitation=0A= of an offer to buy any financial product. Email trans-=0A= mission cannot be guaranteed to be secure or error-=0A= free. P6070214=0A= ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Numpy and iterative procedures
Thanks Chuck. I am trying to use Successive Over-relaxation to solve linear equations defined by M*v=q. There are several goals: 1. Eventually (in production) I need it to be fast. 2. I am playing with the guts of the algorithm for now, to see how it works. that means i need some control for now. 3. Even in production, there is a chance i'd like to have the ability to tinker with the algorithm. _ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Charles R Harris Sent: Thursday, February 15, 2007 10:11 AM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] Numpy and iterative procedures On 2/15/07, Geoffrey Zhu [EMAIL PROTECTED] wrote: Hi, I am new to numpy. I'd like to know if it is possible to code efficient iterative procedures with numpy. Specifically, I have the following problem. M is an N*N matrix. Q is a N*1 vector. V is an N*1 vector I am trying to find iteratively from the initial value V_0. The procedure is simply to calculate V_{n+1}[i]=3D1/M[I,i]*(q[i]- (M[i,1]*v_{n+1}[1]+M[I,2]*v_{n+1}[2]+..+M[i,i-1]*v_{n+1}[i-1]) - (M[I,i+1]*v_{n}[i+1]+M[I,i+2]*v_{n}[i+2]+..+M[I,N]*v_{n}[N])) I do not see that this is something that can esaily be vectorized, is it? I think it would be better if you stated what the actual problem is. Is it a differential equation, for instance. That way we can determine what the problem class is and what algorithms are available to solve it. Chuck ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Confusing selector?
I am really new to numpy but I just found that v[2:4] means selecting v[2] and v[3]. V[4] is not included! This is quite different from the conventions of matlab and R. ___=0A= =0A= The information in this email or in any file attached=0A= hereto is intended only for the personal and confiden-=0A= tial use of the individual or entity to which it is=0A= addressed and may contain information that is propri-=0A= etary and confidential. If you are not the intended=0A= recipient of this message you are hereby notified that=0A= any review, dissemination, distribution or copying of=0A= this message is strictly prohibited. This communica-=0A= tion is for information purposes only and should not=0A= be regarded as an offer to sell or as a solicitation=0A= of an offer to buy any financial product. Email trans-=0A= mission cannot be guaranteed to be secure or error-=0A= free. P6070214=0A= ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion