Re: [Numpy-discussion] Fast function application on list of 2D points?

2009-01-12 Thread Paulo J. S. Silva
Why you don't create a mask to select only the points in array that satisfies the condition on x and y coordinates. For example the code below applies filter only to the values that have x coordinate bigger than 0.7 and y coordinate smaller than 0.3: mask = numpy.logical_and(points[:,0] 0.7,

Re: [Numpy-discussion] Fast function application on list of 2D points?

2009-01-12 Thread Paulo J. S. Silva
Eric, You question raised my attention due to a recent post of mine related to the same kind of problem. I was solving it without using apply_along_axis (due to ignorance). However I tried to use apply_along_axis to solve my problem and it proved to be very slow. Try the following: ---

[Numpy-discussion] 2-D function and meshgrid

2009-01-09 Thread Paulo J. S. Silva
Hello, I have a function that receives a array of shape (2,) and returns a number (a function from R^2 - R). It basically looks like this: def weirdDistance2(x): return dot(dot(weirdMatrix, x), x) (weirdMatrix is a global (2,2) array) I want to see its level sets in the box [0, 1] x

Re: [Numpy-discussion] 2-D function and meshgrid

2009-01-09 Thread Paulo J. S. Silva
Chuck, Thanks, your version is much faster. I would prefer a solution that doesn't force me to re-implement weirdDistance (as my two solutions were). But the function is so simple that it is easier just to re-write it for speed as you did. By the way, I came out with one more solution that looks

Re: [Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-05 Thread Paulo J. S. Silva
x = np.frombuffer(int_asbuffer(C.addressof(x.contents), n*8)) I'll go with your faster solution. Very good. Thank you very much. Paulo ___ Numpy-discussion mailing list Numpy-discussion@scipy.org

[Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-04 Thread Paulo J. S. Silva
Hello, I am writing some code interfacing C and Python using ctypes. In a callback function (in Python) I get in a parameter x which is c_double pointer and a parameter n which is c_int representing the length of the array. How can I transform this information into a numpy array? Paulo

Re: [Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-04 Thread Paulo J. S. Silva
Em Qui, 2008-09-04 às 15:01 -0500, Travis E. Oliphant escreveu: Paulo J. S. Silva wrote: Something like this may work: from numpy import ctypeslib r = ctypeslib.as_array(x._type_ * n) Unfortunately, it didn't work. If that doesn't work, then you can create an array from

Re: [Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-04 Thread Paulo J. S. Silva
, Paulo Em Qui, 2008-09-04 às 17:31 -0400, Paulo J. S. Silva escreveu: Em Qui, 2008-09-04 às 15:01 -0500, Travis E. Oliphant escreveu: Paulo J. S. Silva wrote: Something like this may work: from numpy import ctypeslib r = ctypeslib.as_array(x._type_ * n) Unfortunately

[Numpy-discussion] A bug in scipy.linalg.lu_factor?

2007-01-25 Thread Paulo J. S. Silva
Hello, I am trying to write some unit tests to my new Automatic matrix code and I think I bumped into a bug in scipy.linalg.lu_factor. If you give a matrix to it, it doesn't honor the overwrite_a option: In [1]:import numpy as num In [2]:M = num.mat(num.random.rand(2,2)) In [3]:print M [[

Re: [Numpy-discussion] A bug in scipy.linalg.lu_factor?

2007-01-25 Thread Paulo J. S. Silva
Em Qui, 2007-01-25 às 19:46 +0100, Nils Wagner escreveu: It works if you use M=num.random.rand(2,2) Nils Yes, it works for arrays but not for matrices. I thought that scipy.linalg functions were supposed to work with matrices. Paulo ___