[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) bigarray[current_size:current_size+len(bu

Re: [Numpy-discussion] List with numpy semantics

2010-11-02 Thread Nikolaus Rath
Gerrit Holl writes: > On 31 October 2010 17:10, Nikolaus Rath 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. >>

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

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
Warren Weckesser 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 cross

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
Lane Brooks 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.searchsorte

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
Alan G Isaac writes: > On 8/17/2010 11:53 AM, Nikolaus Rath wrote: >> 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? > > > argmax? (to get i+1): > >>> d = np.lins

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

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

2010-04-28 Thread Nikolaus Rath
Robert Kern 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. http://www.python.org/dev/peps/pep-022

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

2010-04-15 Thread Nikolaus Rath
eat writes: > Nikolaus Rath 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 stil

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

2010-04-15 Thread Nikolaus Rath
Keith Goodman writes: > On Wed, Apr 14, 2010 at 12:39 PM, Nikolaus Rath wrote: >> Keith Goodman writes: >>> On Wed, Apr 14, 2010 at 8:49 AM, Keith Goodman wrote: >>>> On Wed, Apr 14, 2010 at 8:16 AM, Nikolaus Rath wrote: >>>>> Hello, >>

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

2010-04-15 Thread Nikolaus Rath
eat 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 if that's relev

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

2010-04-14 Thread Nikolaus Rath
Keith Goodman writes: > On Wed, Apr 14, 2010 at 8:49 AM, Keith Goodman wrote: >> On Wed, Apr 14, 2010 at 8:16 AM, Nikolaus Rath wrote: >>> Hello, >>> >>> How do I best find out the indices of the largest x elements in an >>> array? &

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