[Numpy-discussion] Pre-allocate array

2012-12-27 Thread Nikolaus Rath
Hello, I have an array that I know will need to grow to X elements. However, I will need to work with it before it's completely filled. I see two ways of doing this: bigarray = np.empty(X) current_size = 0 for i in something: buf = produce_data(i)

Re: [Numpy-discussion] List with numpy semantics

2010-11-02 Thread Nikolaus Rath
Gerrit Holl gerrit.h...@gmail.com writes: On 31 October 2010 17:10, Nikolaus Rath nikol...@rath.org wrote: Hello, I have a couple of numpy arrays which belong together. Unfortunately they have different dimensions, so I can't bundle them into a higher dimensional array. My solution

[Numpy-discussion] List with numpy semantics

2010-10-31 Thread Nikolaus Rath
Hello, I have a couple of numpy arrays which belong together. Unfortunately they have different dimensions, so I can't bundle them into a higher dimensional array. My solution was to put them into a Python list instead. But unfortunately this makes it impossible to use any ufuncs. Has someone

[Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
Hello, I want to find the first i such that x[i] y and x[i+1] = y. Is there a way to do this without using a Python loop? I can't use np.searchsorted(), because my x array crosses y several times. Best, -Nikolaus -- »Time flies like an arrow, fruit flies like a Banana.« PGP

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
Lane Brooks l...@brooks.nu writes: On 08/17/2010 09:53 AM, Nikolaus Rath wrote: Hello, I want to find the first i such that x[i] y and x[i+1]= y. Is there a way to do this without using a Python loop? I can't use np.searchsorted(), because my x array crosses y several times. Best

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
Warren Weckesser warren.weckes...@enthought.com writes: Nikolaus Rath wrote: Hello, I want to find the first i such that x[i] y and x[i+1] = y. Is there a way to do this without using a Python loop? I can't use np.searchsorted(), because my x array crosses y several times. In [34

Re: [Numpy-discussion] proposing a beware of [as]matrix() warning

2010-04-28 Thread Nikolaus Rath
Robert Kern robert.k...@gmail.com writes: Overloading '*' and '**' while convenient does have consequences.   It would be nice if we could have a few more infix operators in Python to allow separation of  element-by-element calculations and dot-product calculations.

Re: [Numpy-discussion] Find indices of largest elements

2010-04-15 Thread Nikolaus Rath
eat e.antero.ta...@gmail.com writes: How do I best find out the indices of the largest x elements in an array? Just a= np.asarray([[1, 8, 2], [2, 1, 3]]) print np.where((a.T== a.max(axis= 1)).T) However, if any row contains more than 1 max entity, above will fail. Please let me to know

Re: [Numpy-discussion] Find indices of largest elements

2010-04-15 Thread Nikolaus Rath
Keith Goodman kwgood...@gmail.com writes: On Wed, Apr 14, 2010 at 12:39 PM, Nikolaus Rath nikol...@rath.org wrote: Keith Goodman kwgood...@gmail.com writes: On Wed, Apr 14, 2010 at 8:49 AM, Keith Goodman kwgood...@gmail.com wrote: On Wed, Apr 14, 2010 at 8:16 AM, Nikolaus Rath nikol

Re: [Numpy-discussion] Find indices of largest elements

2010-04-15 Thread Nikolaus Rath
eat e.antero.ta...@gmail.com writes: Nikolaus Rath Nikolaus at rath.org writes: [snip] Not quite, because I'm interested in the n largest values over all elements, not the largest element in each row or column. But Keith's solution seems to work fine, even though I'm still struggling

[Numpy-discussion] Find indices of largest elements

2010-04-14 Thread Nikolaus Rath
Hello, How do I best find out the indices of the largest x elements in an array? Example: a = [ [1,8,2], [2,1,3] ] magic_function(a, 2) == [ (0,1), (1,2) ] Since the largest 2 elements are at positions (0,1) and (1,2). Best, -Niko -- »Time flies like an arrow, fruit flies like a

Re: [Numpy-discussion] Find indices of largest elements

2010-04-14 Thread Nikolaus Rath
Keith Goodman kwgood...@gmail.com writes: On Wed, Apr 14, 2010 at 8:49 AM, Keith Goodman kwgood...@gmail.com wrote: On Wed, Apr 14, 2010 at 8:16 AM, Nikolaus Rath nikol...@rath.org wrote: Hello, How do I best find out the indices of the largest x elements in an array? Example