[Numpy-discussion] evaluating a function in a matrix element???

2010-03-17 Thread Frank Horowitz
Dear All, I'm working on a piece of optimisation code where it turns out to be mathematically convenient to have a matrix where a few pre-chosen elements must be computed at evaluation time for the dot product (i.e. matrix multiplication) of a matrix with a vector. As I see the problem, there

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Charles R Harris
On Wed, Mar 17, 2010 at 7:39 PM, Darren Dale wrote: > On Wed, Mar 17, 2010 at 8:22 PM, Charles R Harris > wrote: > > > > > > On Wed, Mar 17, 2010 at 5:26 PM, Darren Dale wrote: > >> > >> On Wed, Mar 17, 2010 at 5:43 PM, Charles R Harris > >> wrote: > >> > On Wed, Mar 17, 2010 at 3:13 PM, Darre

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Darren Dale
On Wed, Mar 17, 2010 at 8:22 PM, Charles R Harris wrote: > > > On Wed, Mar 17, 2010 at 5:26 PM, Darren Dale wrote: >> >> On Wed, Mar 17, 2010 at 5:43 PM, Charles R Harris >> wrote: >> > On Wed, Mar 17, 2010 at 3:13 PM, Darren Dale wrote: >> >> On Wed, Mar 17, 2010 at 4:48 PM, Pierre GM >> >> w

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Charles R Harris
On Wed, Mar 17, 2010 at 5:26 PM, Darren Dale wrote: > On Wed, Mar 17, 2010 at 5:43 PM, Charles R Harris > wrote: > > On Wed, Mar 17, 2010 at 3:13 PM, Darren Dale wrote: > >> On Wed, Mar 17, 2010 at 4:48 PM, Pierre GM > wrote: > >> > On Mar 17, 2010, at 8:19 AM, Darren Dale wrote: > >> >> > >>

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Darren Dale
On Wed, Mar 17, 2010 at 5:43 PM, Charles R Harris wrote: > On Wed, Mar 17, 2010 at 3:13 PM, Darren Dale wrote: >> On Wed, Mar 17, 2010 at 4:48 PM, Pierre GM wrote: >> > On Mar 17, 2010, at 8:19 AM, Darren Dale wrote: >> >> >> >> I started thinking about a third method called __input_prepare__ th

Re: [Numpy-discussion] bug in ndarray.resize?

2010-03-17 Thread Charles R Harris
On Wed, Mar 17, 2010 at 8:42 AM, Alan G Isaac wrote: > On 3/17/2010 10:16 AM, josef.p...@gmail.com wrote: > > numpy.resize(a, new_shape) > > Return a new array with the specified shape. > > > > If the new array is larger than the original array, then the new array > > is filled with repeated copi

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Charles R Harris
On Wed, Mar 17, 2010 at 3:13 PM, Darren Dale wrote: > On Wed, Mar 17, 2010 at 4:48 PM, Pierre GM wrote: > > On Mar 17, 2010, at 8:19 AM, Darren Dale wrote: > >> > >> I started thinking about a third method called __input_prepare__ that > >> would be called on the way into the ufunc, which would

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Darren Dale
On Wed, Mar 17, 2010 at 4:48 PM, Pierre GM wrote: > On Mar 17, 2010, at 8:19 AM, Darren Dale wrote: >> >> I started thinking about a third method called __input_prepare__ that >> would be called on the way into the ufunc, which would allow you to >> intercept the input and pass a somehow modified

Re: [Numpy-discussion] f2py compiler version errors

2010-03-17 Thread Pearu Peterson
Hi, You are running rather old numpy version (1.0.1). Try upgrading numpy as at least recent numpy from svn detects this compiler fine. Regards, Pearu Peter Brady wrote: > Hello all, > > The version of f2py that's installed on our system doesn't appear to > handle version numbers correctly. I'v

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Pierre GM
On Mar 17, 2010, at 8:19 AM, Darren Dale wrote: > > I started thinking about a third method called __input_prepare__ that > would be called on the way into the ufunc, which would allow you to > intercept the input and pass a somehow modified copy back to the > ufunc. The total flow would be: > >

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:18, Keith Goodman wrote: > On Wed, Mar 17, 2010 at 12:08 PM, Robert Kern wrote: >> On Wed, Mar 17, 2010 at 14:03, Keith Goodman wrote: >>> On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker >>> wrote: Friedrich Romstedt wrote: > Code: > > import num

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 3:11 PM, Robert Kern wrote: > On Wed, Mar 17, 2010 at 14:07,   wrote: >> On Wed, Mar 17, 2010 at 3:01 PM, Robert Kern wrote: >>> On Wed, Mar 17, 2010 at 14:04, Christopher Barker >>> wrote: Friedrich Romstedt wrote: > Code: > > import numpy > import

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 12:08 PM, Robert Kern wrote: > On Wed, Mar 17, 2010 at 14:03, Keith Goodman wrote: >> On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker >> wrote: >>> Friedrich Romstedt wrote: Code: import numpy import time a = numpy.random.random((2000, 2

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 3:12 PM, Christopher Barker wrote: > Eric Firing wrote: >> My motivation for going >> to the C level was speed and control; many ma operations are very slow >> compared to their numpy counterparts, and moving the mask handling to C >> can erase nearly all of this penalty. >

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Christopher Barker
Robert Kern wrote: > On Wed, Mar 17, 2010 at 14:04, Christopher Barker > wrote: >> though last I checked, it's >> written in Python, > > No, it isn't. > >> and thus not all that fast. > > No, it's reasonably performant. nice to know -- a good while back, I wrote a small collection of add-ons

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:07, wrote: > On Wed, Mar 17, 2010 at 3:01 PM, Robert Kern wrote: >> On Wed, Mar 17, 2010 at 14:04, Christopher Barker >> wrote: >>> Friedrich Romstedt wrote: Code: import numpy import time a = numpy.random.random((2000, 2000))

Re: [Numpy-discussion] matrix operation

2010-03-17 Thread Christopher Barker
Christopher Barker wrote: > In [32]: numpy.minimum(A,B) wow! fifth to answer that one -- darn I'm slow! -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:03, Keith Goodman wrote: > On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker > wrote: >> Friedrich Romstedt wrote: >>> Code: >>> >>> import numpy >>> import time >>> >>> a = numpy.random.random((2000, 2000)) >>> >>> start = time.time() >>> a[abs(a) < 10] = 0 >>> stop

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 3:01 PM, Robert Kern wrote: > On Wed, Mar 17, 2010 at 14:04, Christopher Barker > wrote: >> Friedrich Romstedt wrote: >>> Code: >>> >>> import numpy >>> import time >>> >>> a = numpy.random.random((2000, 2000)) >>> >>> start = time.time() >>> a[abs(a) < 10] = 0 >>> stop =

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Christopher Barker
Eric Firing wrote: > My motivation for going > to the C level was speed and control; many ma operations are very slow > compared to their numpy counterparts, and moving the mask handling to C > can erase nearly all of this penalty. really? very cool. I was thinking about this the other day, and

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker wrote: > Friedrich Romstedt wrote: >> Code: >> >> import numpy >> import time >> >> a = numpy.random.random((2000, 2000)) >> >> start = time.time() >> a[abs(a) < 10] = 0 >> stop = time.time() > > I highly recommend ipython and its "timeit" funct

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:04, Christopher Barker wrote: > Friedrich Romstedt wrote: >> Code: >> >> import numpy >> import time >> >> a = numpy.random.random((2000, 2000)) >> >> start = time.time() >> a[abs(a) < 10] = 0 >> stop = time.time() > > I highly recommend ipython and its "timeit" function

Re: [Numpy-discussion] matrix operation

2010-03-17 Thread Christopher Barker
gerardob wrote: > Let A and B be two n x n matrices. > > I would like to have another n x n matrix C such that > C_ij = min {A_ij, B_ij} In [30]: A = numpy.array([[2,3],[10,12]]) In [31]: B = numpy.array([[1,4],[9,13]]) In [32]: numpy.minimum(A,B) Out[32]: array([[ 1, 3], [ 9, 12]])

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Christopher Barker
Friedrich Romstedt wrote: > Code: > > import numpy > import time > > a = numpy.random.random((2000, 2000)) > > start = time.time() > a[abs(a) < 10] = 0 > stop = time.time() I highly recommend ipython and its "timeit" function --much better for this. And numpy.clip() may be helpful here, though

Re: [Numpy-discussion] matrix operation

2010-03-17 Thread Eric Firing
gerardob wrote: > Let A and B be two n x n matrices. > > I would like to have another n x n matrix C such that > C_ij = min {A_ij, B_ij} > > Example: > A = numpy.array([[2,3],[10,12]]) > B = numpy.array([[1,4],[9,13]]) > > Output > > C = [[1,3],[9,12]] > > The function min(axis) of numpy see

Re: [Numpy-discussion] matrix operation

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 11:47 AM, gerardob wrote: > > Let A and B be two n x n matrices. > > I would like to have another n x n  matrix C such that > C_ij = min {A_ij, B_ij} > > Example: > A = numpy.array([[2,3],[10,12]]) > B = numpy.array([[1,4],[9,13]]) > > Output > > C = [[1,3],[9,12]] > > The

Re: [Numpy-discussion] matrix operation

2010-03-17 Thread Ernest Adrogué
17/03/10 @ 11:47 (-0700), thus spake gerardob: > > Let A and B be two n x n matrices. > > I would like to have another n x n matrix C such that > C_ij = min {A_ij, B_ij} > > Example: > A = numpy.array([[2,3],[10,12]]) > B = numpy.array([[1,4],[9,13]]) > > Output > > C = [[1,3],[9,12]] > > T

Re: [Numpy-discussion] matrix operation

2010-03-17 Thread Ian Mallett
>>> import numpy >>> A = numpy.array([[2,3],[10,12]]) >>> B = numpy.array([[1,4],[9,13]]) >>> C = numpy.array([A,B]) >>> numpy.min(C,0) array([[ 1, 3], [ 9, 12]]) Ian ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.

[Numpy-discussion] matrix operation

2010-03-17 Thread gerardob
Let A and B be two n x n matrices. I would like to have another n x n matrix C such that C_ij = min {A_ij, B_ij} Example: A = numpy.array([[2,3],[10,12]]) B = numpy.array([[1,4],[9,13]]) Output C = [[1,3],[9,12]] The function min(axis) of numpy seems to be only unary. Thanks. -- View thi

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Eric Firing
Charles R Harris wrote: > > > On Wed, Mar 17, 2010 at 6:19 AM, Darren Dale > wrote: > > On Wed, Mar 17, 2010 at 2:07 AM, Pierre GM > wrote: > > All, > > As you're probably aware, the current test suite for numpy.ma >

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Friedrich Romstedt
Code: import numpy import time a = numpy.random.random((2000, 2000)) start = time.time() a[abs(a) < 10] = 0 stop = time.time() print stop - start a = numpy.random.random((2000, 2000)) start = time.time() a = a * (abs(a) >= 10) stop = time.time() print stop - start a = numpy.random.random((2

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 11:56 AM, Keith Goodman wrote: > On Wed, Mar 17, 2010 at 8:51 AM, gerardob wrote: >> >> How can i modified all the values of a numpy array whose value is smaller >> than a given epsilon to zero? >> >> Example >> epsilon=0.01 >> a = [[0.003,2][23,0.0001]] >> >> output: >> [

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 8:51 AM, gerardob wrote: > > How can i modified all the values of a numpy array whose value is smaller > than a given epsilon to zero? > > Example > epsilon=0.01 > a = [[0.003,2][23,0.0001]] > > output: > [[0,2][23,0]] Here's one way: >> a = np.array([[0.003,2],[23,0.0001

Re: [Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread Alan McIntyre
On Wed, Mar 17, 2010 at 8:51 AM, gerardob wrote: > How can i modified all the values of a numpy array whose value is smaller > than a given epsilon to zero? > > Example > epsilon=0.01 > a = [[0.003,2][23,0.0001]] > > output: > [[0,2][23,0]] Give this a try: >>> import numpy as np >>> epsilon=0.0

[Numpy-discussion] Setting small numbers to zero.

2010-03-17 Thread gerardob
How can i modified all the values of a numpy array whose value is smaller than a given epsilon to zero? Example epsilon=0.01 a = [[0.003,2][23,0.0001]] output: [[0,2][23,0]] -- View this message in context: http://old.nabble.com/Setting-small-numbers-to-zero.-tp27933569p27933569.html Sent f

Re: [Numpy-discussion] Problem migrating PDL's index() into NumPy

2010-03-17 Thread Miroslav Sedivy
n0 = 5 # number of rows B = np.ones((n0,3))*np.arange(3) A = np.random.randint(3,size=(n0,3)) C = B[np.arange(n0)[:,None],A] assert (A == C).all() A > array([[2, 0, 1], >[2, 0, 1], >[2, 1, 2], >[0, 0, 2], >[2, 0, 0]]) C > array([[

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Darren Dale
On Wed, Mar 17, 2010 at 10:45 AM, Charles R Harris wrote: > > > On Wed, Mar 17, 2010 at 6:19 AM, Darren Dale wrote: >> >> On Wed, Mar 17, 2010 at 2:07 AM, Pierre GM wrote: >> > All, >> > As you're probably aware, the current test suite for numpy.ma raises >> > some nagging warnings such as "inva

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Ryan May
On Wed, Mar 17, 2010 at 9:20 AM, Darren Dale wrote: > On Wed, Mar 17, 2010 at 10:11 AM, Ryan May wrote: >> On Wed, Mar 17, 2010 at 7:19 AM, Darren Dale wrote: >>> Is this general enough for your use case? I haven't tried to think >>> about how to change some global state at one point and change

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Bruce Southey
On 03/17/2010 01:07 AM, Pierre GM wrote: > All, > As you're probably aware, the current test suite for numpy.ma raises some > nagging warnings such as "invalid value in ...". These warnings are only > issued when a standard numpy ufunc (eg., np.sqrt) is called on a MaskedArray, > instead of its

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Charles R Harris
On Wed, Mar 17, 2010 at 6:19 AM, Darren Dale wrote: > On Wed, Mar 17, 2010 at 2:07 AM, Pierre GM wrote: > > All, > > As you're probably aware, the current test suite for numpy.ma raises > some nagging warnings such as "invalid value in ...". These warnings are > only issued when a standard numpy

Re: [Numpy-discussion] bug in ndarray.resize?

2010-03-17 Thread Alan G Isaac
On 3/17/2010 10:16 AM, josef.p...@gmail.com wrote: > numpy.resize(a, new_shape) > Return a new array with the specified shape. > > If the new array is larger than the original array, then the new array > is filled with repeated copied of a. Note that this behavior is > different from a.resize(new_s

Re: [Numpy-discussion] size of a specific dimension of a numpy array

2010-03-17 Thread Matthieu Brucher
Hi, A.shape[1] 2010/3/17 gerardo.berbeglia : > > I would like to know a simple way to know the size of a given dimension of a > numpy array. > > Example > A = numpy.zeros((10,20,30),float) > The size of the second dimension of the array A is 20. > > Thanks. > > > > > -- > View this message in con

[Numpy-discussion] size of a specific dimension of a numpy array

2010-03-17 Thread gerardo.berbeglia
I would like to know a simple way to know the size of a given dimension of a numpy array. Example A = numpy.zeros((10,20,30),float) The size of the second dimension of the array A is 20. Thanks. -- View this message in context: http://old.nabble.com/size-of-a-specific-dimension-of-a-numpy-

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Darren Dale
On Wed, Mar 17, 2010 at 10:11 AM, Ryan May wrote: > On Wed, Mar 17, 2010 at 7:19 AM, Darren Dale wrote: >> Is this general enough for your use case? I haven't tried to think >> about how to change some global state at one point and change it back >> at another, that seems like a bad idea and diff

Re: [Numpy-discussion] bug in ndarray.resize?

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 10:08 AM, Alan G Isaac wrote: > Is the zero-fill intentional? > If so, it is documented? > (NumPy 1.3) > > Alan Isaac > a = np.arange(5) b = a.copy() c = np.resize(a, (5,2)) b.resize((5,2)) c  # as expected > array([[0, 1], >        [2, 3], >      

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Ryan May
On Wed, Mar 17, 2010 at 7:19 AM, Darren Dale wrote: > Is this general enough for your use case? I haven't tried to think > about how to change some global state at one point and change it back > at another, that seems like a bad idea and difficult to support. Sounds like the textbook use case for

[Numpy-discussion] bug in ndarray.resize?

2010-03-17 Thread Alan G Isaac
Is the zero-fill intentional? If so, it is documented? (NumPy 1.3) Alan Isaac >>> a = np.arange(5) >>> b = a.copy() >>> c = np.resize(a, (5,2)) >>> b.resize((5,2)) >>> c # as expected array([[0, 1], [2, 3], [4, 0], [1, 2], [3, 4]]) >>> b # surprise! array([[0, 1]

Re: [Numpy-discussion] Problem migrating PDL's index() into NumPy

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 9:36 AM, Miroslav Sedivy wrote: > josef.p...@gmail.com wrote: >> On Wed, Mar 17, 2010 at 7:12 AM, Miroslav Sedivy wrote: >>> There are two 2D arrays with dimensions: A[1,1000] and B[1,100]. >>> The first dimension of both arrays corresponds to a list of 1 object

Re: [Numpy-discussion] Problem migrating PDL's index() into NumPy

2010-03-17 Thread Miroslav Sedivy
josef.p...@gmail.com wrote: > On Wed, Mar 17, 2010 at 7:12 AM, Miroslav Sedivy wrote: >> There are two 2D arrays with dimensions: A[1,1000] and B[1,100]. >> The first dimension of both arrays corresponds to a list of 1 objects. >> >> The array A contains for each of 1 objects 1000 i

Re: [Numpy-discussion] Warnings in numpy.ma.test()

2010-03-17 Thread Darren Dale
On Wed, Mar 17, 2010 at 2:07 AM, Pierre GM wrote: > All, > As you're probably aware, the current test suite for numpy.ma raises some > nagging warnings such as "invalid value in ...". These warnings are only > issued when a standard numpy ufunc (eg., np.sqrt) is called on a MaskedArray, > inste

Re: [Numpy-discussion] Problem migrating PDL's index() into NumPy

2010-03-17 Thread josef . pktd
On Wed, Mar 17, 2010 at 7:12 AM, Miroslav Sedivy wrote: > Hello, > > being quite new to NumPy and having used previously PDL in Perl, I am > currently migrating one of my PDL projects into NumPy. > > Most of the functions can be migrated without problems and there are > functions in NumPy that all

[Numpy-discussion] Problem migrating PDL's index() into NumPy

2010-03-17 Thread Miroslav Sedivy
Hello, being quite new to NumPy and having used previously PDL in Perl, I am currently migrating one of my PDL projects into NumPy. Most of the functions can be migrated without problems and there are functions in NumPy that allow me to do things in much clearer way than in PDL. However, I hav