numpy array assignment

John Hunter jdhunter at
Mon Sep 23 10:58:15 EDT 2002

I have a 2 dimensional array X which is NxM and a 1 dimensional array
v which is Nx1.  I want to assign v to the k-th column of X

import Numeric
import RandomArray

Z = Numeric.zeros( (3,10), Numeric.Float  )
v = Numeric.ones( (3,1), Numeric.Float )
Z[:,4] = v

But I get the ValueError: Object too deep for desired array.  I have
read over the numpy manual on slices and array methods and the closest
thing I saw was the 'put' method, but this seems to be designed for 1d

What's the best way to assign an arbitrary Nx1 array to a column of X?

John Hunter

More information about the Python-list mailing list