Re: [Numpy-discussion] numpy speed question

2010-11-25 Thread Ernest Adrogué
Hi, 25/11/10 @ 11:13 (+0100), thus spake Jean-Luc Menut: I suppose that some of the difference may come from the default data type of 64bits in numpy and 32 bits in IDL. Is there a way to change the numpy default data type (without recompiling) ? This is probably not the issue. And I'm

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Ernest Adrogué
22/11/10 @ 11:08 (-0800), thus spake Christopher Barker: On 11/21/10 11:37 AM, Ernest Adrogué wrote: so you want t[:,x,y] I tried that, but it's not the same: In [307]: t[[0,1],x,y] Out[307]: array([1, 7]) In [308]: t[:,x,y] Out[308]: array([[1, 3], [5, 7]]) what

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Ernest Adrogué
22/11/10 @ 11:20 (-0800), thus spake John Salvatier: I didn't realize the x's and y's were varying the first time around. There's probably a way to omit it, but I think the conceptually simplest way is probably what you had to begin with. Build an index by saying i = numpy.arange(0,

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Ernest Adrogué
22/11/10 @ 14:04 (-0600), thus spake Robert Kern: This way, I get the elements (0,1) and (1,1) which is what I wanted. The question is: is it possible to omit the [0,1] in the index? No, but you can write generic code for it: t[np.arange(t.shape[0]), x, y] Thank you. This is what I

[Numpy-discussion] indexing question

2010-11-21 Thread Ernest Adrogué
Hi, Suppose an array of shape (N,2,2), that is N arrays of shape (2,2). I want to select an element (x,y) from each one of the subarrays, so I get a 1-dimensional array of length N. For instance: In [228]: t=np.arange(8).reshape(2,2,2) In [229]: t Out[229]: array([[[0, 1], [2, 3]],

Re: [Numpy-discussion] indexing question

2010-11-21 Thread Ernest Adrogué
Hi, 21/11/10 @ 11:28 (-0800), thus spake John Salvatier: yes use the symbol ':' so you want t[:,x,y] I tried that, but it's not the same: In [307]: t[[0,1],x,y] Out[307]: array([1, 7]) In [308]: t[:,x,y] Out[308]: array([[1, 3], [5, 7]]) No? -- Ernest

Re: [Numpy-discussion] unique 2d arrays

2010-09-21 Thread Ernest Adrogué
21/09/10 @ 12:55 (-0500), thus spake Gökhan Sever: On Tue, Sep 21, 2010 at 12:43 PM, josef.p...@gmail.com wrote: I'm a bit surprised, I think np.unique does some extra work to maintain the order. The tolist() might not be necessary if you iterate over rows. Testing again with a

Re: [Numpy-discussion] indexing with booleans without making a copy?

2010-09-08 Thread Ernest Adrogué
8/09/10 @ 15:35 (-0400), thus spake Anne Archibald: 2010/9/8 Ernest Adrogué eadro...@gmx.net: I have a sorted, flat array: In [139]: a =np.array([0,1,2,2,2,3]) Basically, I want views of the areas where there are repeated numbers (since the array is sorted, they will be contiguous

[Numpy-discussion] test if two arrays share the same data

2010-09-05 Thread Ernest Adrogué
Hi, How can it be done? id() doesn't do it: In [238]: a= np.arange(5) In [239]: id(a) == id(a[:]) Out[239]: False Any ideas? Ernest ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] test if two arrays share the same data

2010-09-05 Thread Ernest Adrogué
5/09/10 @ 21:25 (+0200), thus spake Gael Varoquaux: On Sun, Sep 05, 2010 at 09:12:34PM +0200, Ernest Adrogué wrote: Hi, How can it be done? np.may_share_memory Thanks Gael and Puneeth. I think the .base attribute is enough for what I want. Bye

Re: [Numpy-discussion] test if two arrays share the same data

2010-09-05 Thread Ernest Adrogué
5/09/10 @ 15:59 (-0500), thus spake Robert Kern: 2010/9/5 Ernest Adrogué eadro...@gmx.net:  5/09/10 @ 21:25 (+0200), thus spake Gael Varoquaux: On Sun, Sep 05, 2010 at 09:12:34PM +0200, Ernest Adrogué wrote: Hi, How can it be done? np.may_share_memory Thanks Gael and Puneeth

[Numpy-discussion] comparison between arrays of strings and numerical types

2010-08-31 Thread Ernest Adrogué
Hi, I find this a bit odd: In [18]: np.array(['a','b','c','d']) 'a' Out[18]: array([False, True, True, True], dtype=bool) In [19]: np.array(['a','b','c','d']) 4 Out[19]: True In [20]: np.array(['a','b','c','d']) 4.5 Out[20]: True Is that right? I was expecting an element-wise

Re: [Numpy-discussion] comparison between arrays of strings and numerical types

2010-08-31 Thread Ernest Adrogué
31/08/10 @ 09:44 (-0700), thus spake Keith Goodman: 2010/8/31 Ernest Adrogué eadro...@gmx.net: Hi, I find this a bit odd: In [18]: np.array(['a','b','c','d']) 'a' Out[18]: array([False,  True,  True,  True], dtype=bool) In [19]: np.array(['a','b','c','d']) 4 Out[19]: True

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

2010-08-20 Thread Ernest Adrogué
19/08/10 @ 18:03 (-0600), thus spake Charles R Harris: 2010/8/19 Ernest Adrogué eadro...@gmx.net 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

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

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

[Numpy-discussion] combinatorics

2010-03-04 Thread Ernest Adrogué
Hello everybody, Suppose I want to find all 2-digit numbers whose first digit is either 4 or 5, the second digit being 7, 8 or 9. Is there a Numpy/Scipy function to calculate that kind of combinations? I came up with this function, the problem is it uses recursion: def g(sets): if len(sets)

Re: [Numpy-discussion] combinatorics

2010-03-04 Thread Ernest Adrogué
4/03/10 @ 11:19 (+0100), thus spake Ernest Adrogué: Hello everybody, Suppose I want to find all 2-digit numbers whose first digit is either 4 or 5, the second digit being 7, 8 or 9. Is there a Numpy/Scipy function to calculate that kind of combinations? I came up with this function

Re: [Numpy-discussion] combinatorics

2010-03-04 Thread Ernest Adrogué
4/03/10 @ 12:26 (+0100), thus spake Johan Grönqvist: Ernest Adrogué skrev: Suppose I want to find all 2-digit numbers whose first digit is either 4 or 5, the second digit being 7, 8 or 9. I came up with this function, the problem is it uses recursion: [...] In [157]: g([[4,5

Re: [Numpy-discussion] Apply a function to all indices

2010-02-28 Thread Ernest Adrogué
28/02/10 @ 01:56 (-0500), thus spake David Warde-Farley: On 26-Feb-10, at 8:12 AM, Ernest Adrogué wrote: Thanks for the tip. I didn't know that... Also, frompyfunc appears to crash python when the last argument is 0: In [9]: func=np.frompyfunc(lambda x: x, 1, 0) In [10]: func

Re: [Numpy-discussion] Apply a function to all indices

2010-02-26 Thread Ernest Adrogué
Hi, 26/02/10 @ 11:23 (+0100), thus spake Ole Streicher: Hi, I want to apply a function to all indices of an array that fullfill a certain condition. What I tried: -8 import numpy def myfunc(x): print 'myfunc of', x a =

Re: [Numpy-discussion] Apply a function to all indices

2010-02-26 Thread Ernest Adrogué
26/02/10 @ 13:31 (+0100), thus spake Ole Streicher: Hello Ernest, Ernest Adrogué eadro...@gmx.net writes: It depends on what exactly you want to do. If you just want to iterate over the array, try something liks this for element in a[a 0.8]: myfunc(element) No; I need

Re: [Numpy-discussion] Apply a function to all indices

2010-02-26 Thread Ernest Adrogué
26/02/10 @ 13:51 (+0200), thus spake Pauli Virtanen: pe, 2010-02-26 kello 12:43 +0100, Ernest Adrogué kirjoitti: [clip] Or if you want to produce a different array of the same shape as the original, then you probably need a vectorised function. def myfunc(x): print 'myfunc of', x

Re: [Numpy-discussion] np.bincount raises MemoryError when given an empty array

2010-02-02 Thread Ernest Adrogué
2/02/10 @ 00:01 (-0700), thus spake Charles R Harris: On Mon, Feb 1, 2010 at 10:57 PM, josef.p...@gmail.com wrote: On Tue, Feb 2, 2010 at 12:31 AM, Charles R Harris charlesr.har...@gmail.com wrote: On Mon, Feb 1, 2010 at 10:02 PM, josef.p...@gmail.com wrote: On Mon, Feb 1,

[Numpy-discussion] np.bincount raises MemoryError when given an empty array

2010-02-01 Thread Ernest Adrogué
Hello, Consider the following code: for j in range(5): f = np.bincount(x[y == j]) It fails with MemoryError whenever y == j is all False element-wise. In [96]: np.bincount([]) --- MemoryError

[Numpy-discussion] should numpy.equal raise an exception instead of returning NotImplemented?

2010-01-26 Thread Ernest Adrogué
Hi, Do you think it is sensible for np.equal to return a NotImplemented object when is given an array of variable length dtype? Consider this code: x = np.array(['xyz','zyx']) np.where(np.equal(x, 'zyx'), [0,0], [1,1]) the last line returns array([0, 0]) which is wrong. Compare with np.where(x

Re: [Numpy-discussion] should numpy.equal raise an exception instead of returning NotImplemented?

2010-01-26 Thread Ernest Adrogué
26/01/10 @ 08:59 (-0500), thus spake josef.p...@gmail.com: 2010/1/26 Ernest Adrogué eadro...@gmx.net: Hi, Do you think it is sensible for np.equal to return a NotImplemented object when is given an array of variable length dtype? Consider this code: x = np.array(['xyz','zyx

[Numpy-discussion] strange divergence in performance

2010-01-20 Thread Ernest Adrogué
Hi, I have a function where an array of integers (1-d) is compared element-wise to an integer using the greater-than operator. I noticed that when the integer is 0 it takes about 75% more time than when it's 1 or 2. Is there an explanation? Here is a stripped-down version which does (sort

Re: [Numpy-discussion] strange divergence in performance

2010-01-20 Thread Ernest Adrogué
20/01/10 @ 16:17 (-0600), thus spake Robert Kern: 2010/1/20 Ernest Adrogué eadro...@gmx.net: Hi, I have a function where an array of integers (1-d) is compared element-wise to an integer using the greater-than operator. I noticed that when the integer is 0 it takes about 75% more time

[Numpy-discussion] logic problem

2010-01-18 Thread Ernest Adrogué
Hi, This is hard to explain. In this code: reduce(np.logical_or, [m1 m2, m1 m3, m2 m3]) where m1, m2 and m3 are boolean arrays, I'm trying to figure out an expression that works with an arbitrary number of arrays, not just 3. Any idea?? Bye. ___

Re: [Numpy-discussion] logic problem

2010-01-18 Thread Ernest Adrogué
18/01/10 @ 14:17 (-0500), thus spake josef.p...@gmail.com: 2010/1/18 Ernest Adrogué eadro...@gmx.net: Hi, This is hard to explain. In this code: reduce(np.logical_or, [m1 m2, m1 m3, m2 m3]) where m1, m2 and m3 are boolean arrays, I'm trying to figure out an expression

Re: [Numpy-discussion] logic problem

2010-01-18 Thread Ernest Adrogué
18/01/10 @ 13:18 (-0600), thus spake Warren Weckesser: Ernest Adrogué wrote: Hi, This is hard to explain. In this code: reduce(np.logical_or, [m1 m2, m1 m3, m2 m3]) where m1, m2 and m3 are boolean arrays, I'm trying to figure out an expression that works with an arbitrary

Re: [Numpy-discussion] numpy sum table by category

2010-01-13 Thread Ernest Adrogué
12/01/10 @ 15:33 (-0500), thus spake Marc Schwarzschild: I have a csv file like this: Account, Symbol, Quantity, Price One,SPY,5,119.00 One,SPY,3,120.00 One,SPY,-2,125.00 One,GE,... One,GE,... Two,SPY, ... Three,GE, ... ... The data is much

[Numpy-discussion] is it safe to change the dtype without rebuilding the array?

2010-01-01 Thread Ernest Adrogué
Hi, I find myself doing this: In [244]: x Out[244]: array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) In [245]: y=x.copy() In [251]: y.dtype.char Out[251]: 'l' In [252]: dt=np.dtype([('a','l'),('b','l'),('c','l')]) In [254]: y.dtype=dt Is it okay? The problem is that it's not easy to

Re: [Numpy-discussion] indices of values contained in a list

2009-12-13 Thread Ernest Adrogué
12/12/09 @ 08:16 (-0800), thus spake Keith Goodman: If a and b are as short as in your example, which I doubt, here's a faster way: timeit np.nonzero(reduce(np.logical_or, [a == i for i in b])) 10 loops, best of 3: 14 µs per loop timeit [i for i, z in enumerate(a) if z in b] 10

[Numpy-discussion] indices of values contained in a list

2009-12-12 Thread Ernest Adrogué
Hi, Suppose I have a flat array, and I want to know the indices corresponding to values contained in a list of arbitrary lenght. Intuitively I would have done: a = np.array([1,2,3,4]) np.nonzero(a in (0,2,4)) However the in operator doesn't work element-wise, instead it compares the whole

Re: [Numpy-discussion] slices of structured arrays?

2009-12-09 Thread Ernest Adrogué
9/12/09 @ 00:45 (-0500), thus spake josef.p...@gmail.com: as long as all numbers are of the same type, you can create a view that behaves (mostly) like a regular array [...] Thanks Josef. Great explanation. It's all clear now. Ernest ___

[Numpy-discussion] histogram for discrete data

2009-12-06 Thread Ernest Adrogué
Hi, A few weeks ago there was a discussion about a histogram_discrete() function --sorry for starting a new thread but I have lost the mails. Somebody pointed out that bincount() already can be used to histogram discrete data (except that it doesn't work with negative values). I have just

Re: [Numpy-discussion] Initial implementation of histogram_discrete()

2009-11-13 Thread Ernest Adrogué
13/11/09 @ 09:41 (+0200), thus spake Priit Laes: Does anyone have a scenario where one would actually have both negative and positive numbers (integers) in the list? Yes: when you have a random variable that is the difference of two (discrete) random variables. For example, if you measure the

[Numpy-discussion] masked arrays as array indices

2009-09-21 Thread Ernest Adrogué
Hello there, Given a masked array such as this one: In [19]: x = np.ma.masked_equal([-1, -1, 0, -1, 2], -1) In [20]: x Out[20]: masked_array(data = [-- -- 0 -- 2], mask = [ True True False True False], fill_value = 99) When you make an assignemnt in the vein of x[x

Re: [Numpy-discussion] masked arrays as array indices (is a bad idea)

2009-09-21 Thread Ernest Adrogué
21/09/09 @ 14:43 (-0400), thus spake Pierre GM: On Sep 21, 2009, at 12:17 PM, Ryan May wrote: 2009/9/21 Ernest Adrogué eadro...@gmx.net Hello there, Given a masked array such as this one: In [19]: x = np.ma.masked_equal([-1, -1, 0, -1, 2], -1) In [20]: x Out[20

[Numpy-discussion] array multiplication

2009-09-16 Thread Ernest Adrogué
Hi, I have two 1-d arrays (a and b), and I want to create a third 2-d array, whose rows are of the form a[i]*b: c = np.zeros((len(a),b)) c[0] = a[0]*b c[1] = a[1]*b . . . Is there an easy way to do this (e.g, without a loop)? Thanks! -- Ernest ___

Re: [Numpy-discussion] object dtype questions

2009-09-06 Thread Ernest Adrogué
5/09/09 @ 11:22 (-0600), thus spake Mark Wendell: For example: Say that C is a simple python class with a couple attributes and methods. a = np.empty( (5,5), dtype=object) for i in range(5): for j in range(5): a[i,j] = C(var1,var2) First question: is there a quicker

Re: [Numpy-discussion] masked arrays of structured arrays

2009-09-02 Thread Ernest Adrogué
31/08/09 @ 14:37 (-0400), thus spake Pierre GM: On Aug 31, 2009, at 2:33 PM, Ernest Adrogué wrote: 30/08/09 @ 13:19 (-0400), thus spake Pierre GM: I can't reproduce that with a recent SVN version (r7348). What version of numpy are you using ? Version 1.2.1 That must

Re: [Numpy-discussion] masked arrays of structured arrays

2009-08-31 Thread Ernest Adrogué
30/08/09 @ 13:19 (-0400), thus spake Pierre GM: I can't reproduce that with a recent SVN version (r7348). What version of numpy are you using ? Version 1.2.1 -- Ernest ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org

[Numpy-discussion] masked arrays of structured arrays

2009-08-22 Thread Ernest Adrogué
Hi there, Here is a structured array with 3 fields each of which has 3 fields in turn: In [3]: desc = [('a',int), ('b',int), ('c',int)] In [4]: desc = [('x',desc), ('y',desc), ('z',desc)] With a regular ndarray it works just fine: In [11]: x = np.zeros(2, dtype=desc) In [12]: x['x']['b'] = 2

Re: [Numpy-discussion] how to find array indices at which a condition is satisfied?

2009-08-20 Thread Ernest Adrogué
20/08/09 @ 18:00 (-0700), thus spake Dr. Phillip M. Feldman: I have a 1-D array and would like to generate a list of indices for which a given condition is satisfied. What is the cleanest way to do this? you can do something like this: numpy.arange(len(x))[x 5] it'll give you the indices of

[Numpy-discussion] indexing problem

2009-08-18 Thread Ernest Adrogué
Hi, Suppose I have a 3-dimansional array, where one dimension is time. I'm not particularly interested in selecting specific moments in time, so most of the time I won't be indexing this dimension. Intuitively, one would make time the third dimension, but if you do that you have to specifiy the

Re: [Numpy-discussion] indexing problem

2009-08-18 Thread Ernest Adrogué
18/08/09 @ 07:33 (-0700), thus spake Robert Kern: 2009/8/18 Ernest Adrogué eadro...@gmx.net: Hi, Suppose I have a 3-dimansional array, where one dimension is time. I'm not particularly interested in selecting specific moments in time, so most of the time I won't be indexing

Re: [Numpy-discussion] question about a data structure

2009-07-30 Thread Ernest Adrogué
29/07/09 @ 14:54 (-0700), thus spake Christopher Barker: Robert Kern wrote: 2009/7/29 Ernest Adrogué eadro...@gmx.net: Now, I need to be able to differentiate between 0 and 'no data'. Is it possible to do this with the standard array class? Not really. Use masked arrays. Or use

[Numpy-discussion] question about a data structure

2009-07-29 Thread Ernest Adrogué
Hello, Suppose I want to store some data (a non-negative integer) related to an event involving two entities. It occurs to me that the way to do it is using a 2-d array, like a table: For example: a b c a1 b 2 0 c 5 in the event 'b-a' the data is 2, and in the event 'c-a' is