Re: [Numpy-discussion] index of the first element fulfilling a condition?

2010-08-19 Thread Erin Sheldon
Excerpts from Johann Bauer's message of Wed Aug 18 14:07:48 -0400 2010: > Hi, > > is there a good method to find the index of the first element in a 1D > array fulfilling a condition? > > The following does the job > > >>> import numpy > >>> a = numpy.array([1,5,78,3,12,4]) > >>> numpy.where( a

Re: [Numpy-discussion] numpy.concatenate slower than slice copying

2010-08-19 Thread Francesc Alted
2010/8/18, Zbyszek Szmek : > thank you for your detailed answer. It seems that memcpy which should always > be faster then memmove is sometimes slower! What happens is that > using the slice assignment calls memmove() which calls > _wordcopy_fwd_aligned() [1] > which is apparently faster than memcp

Re: [Numpy-discussion] index of the first element fulfilling a condition?

2010-08-19 Thread Francesc Alted
2010/8/18, Johann Bauer : > Hi, > > is there a good method to find the index of the first element in a 1D > array fulfilling a condition? > > The following does the job > import numpy a = numpy.array([1,5,78,3,12,4]) numpy.where( a>10 )[0][0] > 2 > > but it first compares the entire

Re: [Numpy-discussion] lexsort() of datetime objects doesn't work

2010-08-19 Thread Charles R Harris
2010/8/19 Ernest Adrogué > Hi, > > I was trying to use lexsort with an array of > datetime.date objects, but it doesn't seem to work. > > In [86]: date = np.array([datetime.date(2000, 9, 17), > datetime.date(2000, 10, 1), > datetime.date(2000, 10, 22), > datetime.date(2000, 11, 1)]) > > In [90

[Numpy-discussion] lexsort() of datetime objects doesn't work

2010-08-19 Thread Ernest Adrogué
Hi, I was trying to use lexsort with an array of datetime.date objects, but it doesn't seem to work. In [86]: date = np.array([datetime.date(2000, 9, 17), datetime.date(2000, 10, 1), datetime.date(2000, 10, 22), datetime.date(2000, 11, 1)]) In [90]: date Out[90]: array([2000-09-17, 2000-10-01

Re: [Numpy-discussion] max value of an array of lists

2010-08-19 Thread sm lkd
No need any more. Thank you anyway! --sv Date: Thu, 19 Aug 2010 14:44:14 -0700 From: jsalv...@u.washington.edu To: numpy-discussion@scipy.org Subject: Re: [Numpy-discussion] max value of an array of lists You have an object array of lists? Why? On Thu, Aug 19, 2010 at 2:41 PM, sm lkd wro

Re: [Numpy-discussion] vectorization of vectorization

2010-08-19 Thread sm lkd
With slight modification I got it work (fucnt as before): funct(orders, num.arange(1e6)[:, num.newaxis], powers).prod(axis = 1) This gives me exactly what I need! Thanks a lot. ps: I don't know how to post my thank you on the discussion list. Date: Thu, 19 Aug 2010 14:32:42 -0700 From:

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread Bruce Southey
On 08/19/2010 04:20 PM, josef.p...@gmail.com wrote: On Thu, Aug 19, 2010 at 4:03 PM, John Salvatier wrote: Precise in what sense? Numerical accuracy? If so, why is that? I don't remember where I ran into this example, maybe integer underflow (?) with addition. NIST ANOVA test cases have some

Re: [Numpy-discussion] max value of an array of lists

2010-08-19 Thread John Salvatier
It sounds like you should just have a higher dimensional array. A 2 or 3 dimensional array instead of an object array. On Thu, Aug 19, 2010 at 2:44 PM, John Salvatier wrote: > You have an object array of lists? Why? > > On Thu, Aug 19, 2010 at 2:41 PM, sm lkd wrote: > >> Hello again, >> >> Here

Re: [Numpy-discussion] max value of an array of lists

2010-08-19 Thread John Salvatier
You have an object array of lists? Why? On Thu, Aug 19, 2010 at 2:41 PM, sm lkd wrote: > Hello again, > > Here's a simple one. I have an array/matrix of lists (floats). array.max() > or max(array) returns list (!) and not an individual value. Of course, it is > possible to loop, but maybe someo

[Numpy-discussion] max value of an array of lists

2010-08-19 Thread sm lkd
Hello again, Here's a simple one. I have an array/matrix of lists (floats). array.max() or max(array) returns list (!) and not an individual value. Of course, it is possible to loop, but maybe someone knows a better way to do the same. Thanks, __

Re: [Numpy-discussion] vectorization of vectorization

2010-08-19 Thread John Salvatier
This seems simple, so perhaps I am missing something, but what about this: special.iv(orders[:, newaxis], arange(1e6)[newaxis, : ], powers[:, newaxis]).prod(axis = 2) This will probably use up a bit slow/memoryintensive, so you probably want to use numexpr to speed it up a bit. On Thu, Aug 19, 2

Re: [Numpy-discussion] vectorization of vectorization

2010-08-19 Thread Scott Ransom
If you use already vectorized functions (like special.iv) you often don't need to use vectorization() For example: - import numpy as num import scipy.special as special def funct(order, t, power): return special.iv(order, t)**power order = num.arange(4.0) ts = n

[Numpy-discussion] vectorization of vectorization

2010-08-19 Thread sm lkd
Hello, Here's my problem: for each value t of an array (from 0 to 1e6) a smaller array is computed (size between 2-6). To compute the smaller array, I have a function (which can be easily vectorized if necessary) which takes t and an array of powers of t. The return is an array of modified Be

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread josef . pktd
On Thu, Aug 19, 2010 at 4:03 PM, John Salvatier wrote: > Precise in what sense? Numerical accuracy? If so, why is that? I don't remember where I ran into this example, maybe integer underflow (?) with addition. NIST ANOVA test cases have some nasty badly scaled variables but I have problems crea

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread Jeremiah
Word size. imagine 2.123456789 vs 22.12345679 the more that can stored to the right of the decimal, the more precise. That larger the number is on the left, the less that can stored on the right. On Thu, Aug 19, 2010 at 4:03 PM, John Salvatier wrote: > Precise in what sense? Numerical accuracy

[Numpy-discussion] Using numpy's flatten_dtype with structured dtypes that have titles

2010-08-19 Thread Emma Willemsma
Hi, I originally posted this question on stackoverflow, and the user who responded to me suggested that I bring this issue to the attention of the numpy developers. I am working with structured arrays to store experimental data. I'm using titles to store information about my fields, in this case

Re: [Numpy-discussion] loading database data into numpy arrays

2010-08-19 Thread John Salvatier
I found the cause of the original problem. pyodbc.cursor.next() returns a pyodbc.Row object, which numpy does not seem to know how to deal with but is essentially an extended tuple. Therefore in order to use the fromiter method to make a numpy structured array from a mysql or other db query, you mu

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread John Salvatier
Precise in what sense? Numerical accuracy? If so, why is that? On Thu, Aug 19, 2010 at 12:13 PM, wrote: > On Thu, Aug 19, 2010 at 11:29 AM, Joe Harrington > wrote: > > On Thu, 19 Aug 2010 09:06:32 -0500, G?khan Sever > wrote: > > > >>On Thu, Aug 19, 2010 at 9:01 AM, greg whittier wrote: > >>

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread josef . pktd
On Thu, Aug 19, 2010 at 11:29 AM, Joe Harrington wrote: > On Thu, 19 Aug 2010 09:06:32 -0500, G?khan Sever > wrote: > >>On Thu, Aug 19, 2010 at 9:01 AM, greg whittier wrote: >> >>> I frequently deal with 3D data and would like to sum (or find the >>> mean, etc.) over the last two axes.  I.e. su

Re: [Numpy-discussion] NumPy-Discussion Digest, Vol 47, Issue 47

2010-08-19 Thread David Goldsmith
Date: Wed, 18 Aug 2010 09:20:41 +0200 > From: Sturla Molden > Subject: Re: [Numpy-discussion] [SciPy-Dev] Good-bye, sort of (John >Hunter) > To: Discussion of Numerical Python > Message-ID: <8c0b2317-2a22-4828-99e8-ac6c0f778...@molden.no> > Content-Type: text/plain; charset=us-asci

Re: [Numpy-discussion] loading database data into numpy arrays

2010-08-19 Thread John Salvatier
That worked! Thanks! On Thu, Aug 19, 2010 at 10:18 AM, Keith Goodman wrote: > On Thu, Aug 19, 2010 at 10:00 AM, John Salvatier > wrote: > > Hello, > > > > I am trying to load some time series data into numpy arrays from a MySQL > > database using pyodbc, but I am not sure what the standard way

Re: [Numpy-discussion] loading database data into numpy arrays

2010-08-19 Thread Keith Goodman
On Thu, Aug 19, 2010 at 10:00 AM, John Salvatier wrote: > Hello, > > I am trying to load some time series data into numpy arrays from a MySQL > database using pyodbc, but I am not sure what the standard way to do this > is. I found the following: > http://www.aidanfindlater.com/python-db-api-to-nu

[Numpy-discussion] loading database data into numpy arrays

2010-08-19 Thread John Salvatier
Hello, I am trying to load some time series data into numpy arrays from a MySQL database using pyodbc, but I am not sure what the standard way to do this is. I found the following: http://www.aidanfindlater.com/python-db-api-to-numpy but when I tried after doing a select (I made sure the cursor ha

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread Joe Harrington
On Thu, 19 Aug 2010 09:06:32 -0500, G?khan Sever wrote: >On Thu, Aug 19, 2010 at 9:01 AM, greg whittier wrote: > >> I frequently deal with 3D data and would like to sum (or find the >> mean, etc.) over the last two axes. I.e. sum a[i,j,k] over j and k. >> I find using .sum() really convenient f

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread Dave
greg whittier gmail.com> writes: > > a = np.arange(27).reshape(3,3,3) > > # sum over axis 1 and 2 > result = a.reshape((a.shape[0], a.shape[1]*a.shape[2])).sum(axis=1) > > Is there a cleaner way to do this? I'm sure I'm missing something obvious. > Only slightly more convenient is: a.reshape

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread greg whittier
On Thu, Aug 19, 2010 at 10:12 AM, Angus McMorland wrote: > Another rank-generic approach is to use apply_over_axes (you get a > different shape to the result this way): > > a = np.random.randint(20, size=(4,3,5)) > b = np.apply_over_axes(np.sum, a, [1,2]).flat > assert( np.all( b == a.sum(axis=2).

Re: [Numpy-discussion] inconsistency in 10**(-2) or 10**array([-2])

2010-08-19 Thread Ralf Gommers
On Wed, Aug 18, 2010 at 9:40 PM, Mark Bakker wrote: > I understand why numpy does it, but even Python itself gives 10**-2 = 0.01. > So I am wondering whether this is the intended behavior of numpy. I don't > really think so, but I may be wrong. > > Was intended, but should probably be changed: ht

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread Angus McMorland
On 19 August 2010 10:01, greg whittier wrote: > I frequently deal with 3D data and would like to sum (or find the > mean, etc.) over the last two axes.  I.e. sum a[i,j,k] over j and k. > I find using .sum() really convenient for 2d arrays but end up > reshaping 2d arrays to do this.  I know there

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread Gökhan Sever
On Thu, Aug 19, 2010 at 9:01 AM, greg whittier wrote: > I frequently deal with 3D data and would like to sum (or find the > mean, etc.) over the last two axes. I.e. sum a[i,j,k] over j and k. > I find using .sum() really convenient for 2d arrays but end up > reshaping 2d arrays to do this. I kn

Re: [Numpy-discussion] summing over more than one axis

2010-08-19 Thread Ian Mallett
Hi, Couldn't you do it with several sum steps? E.g.: result = array.sum(axis=1).sum(axis=2) Ian ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

[Numpy-discussion] summing over more than one axis

2010-08-19 Thread greg whittier
I frequently deal with 3D data and would like to sum (or find the mean, etc.) over the last two axes. I.e. sum a[i,j,k] over j and k. I find using .sum() really convenient for 2d arrays but end up reshaping 2d arrays to do this. I know there has to be a more convenient way. Here's what I'm doing

Re: [Numpy-discussion] ANN: NumPy 1.5.0 beta 2

2010-08-19 Thread Christoph Gohlke
On 8/18/2010 6:00 AM, Charles R Harris wrote: > > > On Wed, Aug 18, 2010 at 6:50 AM, Charles R Harris > mailto:charlesr.har...@gmail.com>> wrote: > > > > On Wed, Aug 18, 2010 at 12:18 AM, Christoph Gohlke > wrote: > > > > On 8/17/2010 9:56 PM, Charles R Ha