setting and getting column in numpymatrix
Boris Borcic
bborcic at gmail.com
Thu Nov 1 18:47:30 EDT 2007
devnew at gmail.com wrote:
> hi
> i am looking for an efficient way to get a specific column of a
> numpy.matrix ..
> also i want to set a column of the matrix with a given set of
> values ..i couldn't find any methods for this in matrix doc..do i have
> to write the functions from scratch?
>
> TIA
> dn
>
>>> from numpy import matrix
>>> x=matrix([[1,2,3],[4,5,6],[7,8,9]])
>>> x[:,1]
matrix([[2],
[5],
[8]])
>>> x[:,1].transpose()
matrix([[2, 5, 8]])
>>> matrix([11,12,13]).transpose()
matrix([[11],
[12],
[13]])
>>> x[:,1] = matrix([11,12,13]).transpose()
>>> x
matrix([[ 1, 11, 3],
[ 4, 12, 6],
[ 7, 13, 9]])
More information about the Python-list
mailing list