broadcasting question
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 to omit B (for debug), like: C = A[:,newaxis,:] In other words, all I want is to add a dimension into A and force it to broadcast along that axis. How do I do that?
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 (i, state, symbol)
That works fine.
Now suppose I want to omit B (for debug), like:
C = A[:,newaxis,:]
In other words, all I want is to add a dimension into A and force it to broadcast along that axis. How do I do that?
np.tile would help you there, I think. Ben Root
On Thu, Aug 30, 2012 at 12:49 PM, Neal Becker <ndbecker2@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,:,:] where C has indexes (i, state, symbol)
That works fine.
Now suppose I want to omit B (for debug), like:
C = A[:,newaxis,:]
In other words, all I want is to add a dimension into A and force it to broadcast along that axis. How do I do that?
C, dummy = numpy.broadcast_arrays(A[:,newaxis,:], numpy.empty([1,state,1])) -- Robert Kern
participants (3)
-
Benjamin Root
-
Neal Becker
-
Robert Kern