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 > > However,it seems I should be able to broadcast that, so I don't have to > repeat myself, but I can't figure out how.
All you need is a newaxis on A2: In [2]: A = np.zeros((3,4)) In [3]: B = np.ones(3) In [4]: A[:,:] = B[:,np.newaxis] In [5]: A Out[5]: array([[ 1., 1., 1., 1.], [ 1., 1., 1., 1.], [ 1., 1., 1., 1.]]) Anne _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion