[Numpy-discussion] broadcasting question

2012-08-30 Thread Neal Becker
I think this should be simple, but I'm drawing a blank I have 2 2d matrixes Matrix A has indexes (i, symbol) Matrix B has indexes (state, symbol) I combined them into a 3d matrix: C = A[:,newaxis,:] + B[newaxis,:,:] where C has indexes (i, state, symbol) That works fine. Now suppose I want

Re: [Numpy-discussion] broadcasting question

2012-08-30 Thread Benjamin Root
On Thursday, August 30, 2012, Neal Becker wrote: I think this should be simple, but I'm drawing a blank I have 2 2d matrixes Matrix A has indexes (i, symbol) Matrix B has indexes (state, symbol) I combined them into a 3d matrix: C = A[:,newaxis,:] + B[newaxis,:,:] where C has indexes

Re: [Numpy-discussion] broadcasting question

2012-08-30 Thread Robert Kern
On Thu, Aug 30, 2012 at 12:49 PM, Neal Becker ndbeck...@gmail.com wrote: I think this should be simple, but I'm drawing a blank I have 2 2d matrixes Matrix A has indexes (i, symbol) Matrix B has indexes (state, symbol) I combined them into a 3d matrix: C = A[:,newaxis,:] + B[newaxis,:,:]

[Numpy-discussion] Broadcasting question

2008-12-04 Thread Olivier Grisel
Hi list, Suppose I have array a with dimensions (d1, d3) and array b with dimensions (d2, d3). I want to compute array c with dimensions (d1, d2) holding the squared euclidian norms of vectors in a and b with size d3. My first take was to use a python level loop: from numpy import * c =

Re: [Numpy-discussion] Broadcasting question

2008-12-04 Thread Stéfan van der Walt
Hi Olivier 2008/12/4 Olivier Grisel [EMAIL PROTECTED]: To avoid the python level loop I then tried to use broadcasting as follows: c = sum((a[:,newaxis,:] - b) ** 2, axis=2) But this build a useless and huge (d1, d2, d3) temporary array that does not fit in memory for large values of d1, d2

Re: [Numpy-discussion] Broadcasting question

2008-12-04 Thread Olivier Grisel
2008/12/4 Stéfan van der Walt [EMAIL PROTECTED]: Hi Olivier 2008/12/4 Olivier Grisel [EMAIL PROTECTED]: To avoid the python level loop I then tried to use broadcasting as follows: c = sum((a[:,newaxis,:] - b) ** 2, axis=2) But this build a useless and huge (d1, d2, d3) temporary array that

Re: [Numpy-discussion] Broadcasting question

2008-12-04 Thread Charles R Harris
On Thu, Dec 4, 2008 at 8:26 AM, Olivier Grisel [EMAIL PROTECTED]wrote: Hi list, Suppose I have array a with dimensions (d1, d3) and array b with dimensions (d2, d3). I want to compute array c with dimensions (d1, d2) holding the squared euclidian norms of vectors in a and b with size d3.

Re: [Numpy-discussion] Broadcasting question

2008-12-04 Thread Olivier Grisel
2008/12/4 Charles R Harris [EMAIL PROTECTED]: On Thu, Dec 4, 2008 at 8:26 AM, Olivier Grisel [EMAIL PROTECTED] wrote: Hi list, Suppose I have array a with dimensions (d1, d3) and array b with dimensions (d2, d3). I want to compute array c with dimensions (d1, d2) holding the squared

Re: [Numpy-discussion] Broadcasting question

2008-05-02 Thread Anne Archibald
2008/5/2 Chris.Barker [EMAIL PROTECTED]: Hi all, I have a n X m X 3 array, and I a n X M array. I want to assign the values in the n X m to all three of the slices in the bigger array: A1 = np.zeros((5,4,3)) A2 = np.ones((5,4)) A1[:,:,0] = A2 A1[:,:,1] = A2 A1[:,:,2] = A2

Re: [Numpy-discussion] Broadcasting question

2008-05-02 Thread Christopher Barker
Charles R Harris wrote: A1 += A2[:,:,newaxis] is one way. Exactly what I was looking for -- thanks Charles (and Ann) -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

[Numpy-discussion] Broadcasting question

2008-05-01 Thread Chris.Barker
Hi all, I have a n X m X 3 array, and I a n X M array. I want to assign the values in the n X m to all three of the slices in the bigger array: A1 = np.zeros((5,4,3)) A2 = np.ones((5,4)) A1[:,:,0] = A2 A1[:,:,1] = A2 A1[:,:,2] = A2 However,it seems I should be able to broadcast that, so I

Re: [Numpy-discussion] Broadcasting question

2008-05-01 Thread Charles R Harris
On Thu, May 1, 2008 at 10:58 PM, Chris.Barker [EMAIL PROTECTED] wrote: Hi all, I have a n X m X 3 array, and I a n X M array. I want to assign the values in the n X m to all three of the slices in the bigger array: A1 = np.zeros((5,4,3)) A2 = np.ones((5,4)) A1[:,:,0] = A2 A1[:,:,1] = A2