[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

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 pgmdevl...@gmail.com 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

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 integer

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 miroslav.sed...@weather-consult.com 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

[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], [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 dsdal...@gmail.com 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

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 ais...@american.edu 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],        [4, 0],

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 rma...@gmail.com wrote: On Wed, Mar 17, 2010 at 7:19 AM, Darren Dale dsdal...@gmail.com 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

[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:

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 gberbeg...@gmail.com: 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

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_shape)

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 dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 2:07 AM, Pierre GM pgmdevl...@gmail.com 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

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 Ryan May
On Wed, Mar 17, 2010 at 9:20 AM, Darren Dale dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 10:11 AM, Ryan May rma...@gmail.com wrote: On Wed, Mar 17, 2010 at 7:19 AM, Darren Dale dsdal...@gmail.com wrote: Is this general enough for your use case? I haven't tried to think about how to

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 charlesr.har...@gmail.com wrote: On Wed, Mar 17, 2010 at 6:19 AM, Darren Dale dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 2:07 AM, Pierre GM pgmdevl...@gmail.com wrote: All, As you're probably aware, the current test suite for

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([[ 2., 0., 1.], [ 2., 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

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

2010-03-17 Thread Alan McIntyre
On Wed, Mar 17, 2010 at 8:51 AM, gerardob gberbeg...@gmail.com 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

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

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 8:51 AM, gerardob gberbeg...@gmail.com 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 =

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 kwgood...@gmail.com wrote: On Wed, Mar 17, 2010 at 8:51 AM, gerardob gberbeg...@gmail.com 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 =

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-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

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

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]] The function

Re: [Numpy-discussion] matrix operation

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 11:47 AM, gerardob gberbeg...@gmail.com 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]]

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 seems to be only

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 last I

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 Robert Kern
On Wed, Mar 17, 2010 at 14:04, Christopher Barker chris.bar...@noaa.gov 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] Setting small numbers to zero.

2010-03-17 Thread Keith Goodman
On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker chris.bar...@noaa.gov 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] 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 josef . pktd
On Wed, Mar 17, 2010 at 3:01 PM, Robert Kern robert.k...@gmail.com wrote: On Wed, Mar 17, 2010 at 14:04, Christopher Barker chris.bar...@noaa.gov wrote: Friedrich Romstedt wrote: Code: import numpy import time a = numpy.random.random((2000, 2000)) start = time.time() a[abs(a) 10] = 0

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

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:03, Keith Goodman kwgood...@gmail.com wrote: On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker chris.bar...@noaa.gov wrote: Friedrich Romstedt wrote: Code: import numpy import time a = numpy.random.random((2000, 2000)) start = time.time() a[abs(a) 10] = 0

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/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA

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

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:07, josef.p...@gmail.com wrote: On Wed, Mar 17, 2010 at 3:01 PM, Robert Kern robert.k...@gmail.com wrote: On Wed, Mar 17, 2010 at 14:04, Christopher Barker chris.bar...@noaa.gov wrote: Friedrich Romstedt wrote: Code: import numpy import time a =

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 chris.bar...@noaa.gov 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

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 chris.bar...@noaa.gov 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

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 robert.k...@gmail.com wrote: On Wed, Mar 17, 2010 at 14:03, Keith Goodman kwgood...@gmail.com wrote: On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker chris.bar...@noaa.gov wrote: Friedrich Romstedt wrote: Code: import numpy import time a

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 robert.k...@gmail.com wrote: On Wed, Mar 17, 2010 at 14:07,  josef.p...@gmail.com wrote: On Wed, Mar 17, 2010 at 3:01 PM, Robert Kern robert.k...@gmail.com wrote: On Wed, Mar 17, 2010 at 14:04, Christopher Barker chris.bar...@noaa.gov wrote:

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

2010-03-17 Thread Robert Kern
On Wed, Mar 17, 2010 at 14:18, Keith Goodman kwgood...@gmail.com wrote: On Wed, Mar 17, 2010 at 12:08 PM, Robert Kern robert.k...@gmail.com wrote: On Wed, Mar 17, 2010 at 14:03, Keith Goodman kwgood...@gmail.com wrote: On Wed, Mar 17, 2010 at 12:04 PM, Christopher Barker chris.bar...@noaa.gov

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: 1)

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've

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 pgmdevl...@gmail.com 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

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 dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 4:48 PM, Pierre GM pgmdevl...@gmail.com 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

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 ais...@american.edu 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

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 charlesr.har...@gmail.com wrote: On Wed, Mar 17, 2010 at 3:13 PM, Darren Dale dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 4:48 PM, Pierre GM pgmdevl...@gmail.com wrote: On Mar 17, 2010, at 8:19 AM, Darren Dale wrote: I started

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 dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 5:43 PM, Charles R Harris charlesr.har...@gmail.com wrote: On Wed, Mar 17, 2010 at 3:13 PM, Darren Dale dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 4:48 PM, Pierre GM pgmdevl...@gmail.com

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 charlesr.har...@gmail.com wrote: On Wed, Mar 17, 2010 at 5:26 PM, Darren Dale dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 5:43 PM, Charles R Harris charlesr.har...@gmail.com wrote: On Wed, Mar 17, 2010 at 3:13 PM, Darren Dale

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 dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 8:22 PM, Charles R Harris charlesr.har...@gmail.com wrote: On Wed, Mar 17, 2010 at 5:26 PM, Darren Dale dsdal...@gmail.com wrote: On Wed, Mar 17, 2010 at 5:43 PM, Charles R Harris