setting items in a matrix
hi i am a beginner with numpy and python,so pardon me if this doubt seems silly i want to create a matrix with say 3 rows and 5 columns..and then set the values of each item in it .for this i did something like below myarray=zeros((3,5)) #then set the items for row in range(3): for col in range(5): myarray[row][col]=999999.9999 mymatrix=matrix(myarray) is this the way to do the matrix creation and value setting? is the use of zeros() unnecessary? i am in the early learning stage so your reply wd help me much dn
or, you can either use fill. In [53]: M = numpy.matrix(numpy.zeros((3,5))) In [55]: M.fill(999) In [56]: M Out[56]: matrix([[ 999., 999., 999., 999., 999.], [ 999., 999., 999., 999., 999.], [ 999., 999., 999., 999., 999.]]) L. On 12/21/07, devnew@gmail.com <devnew@gmail.com> wrote:
hi i am a beginner with numpy and python,so pardon me if this doubt seems silly i want to create a matrix with say 3 rows and 5 columns..and then set the values of each item in it .for this i did something like below
myarray=zeros((3,5)) #then set the items for row in range(3): for col in range(5): myarray[row][col]=999999.9999
mymatrix=matrix(myarray)
is this the way to do the matrix creation and value setting? is the use of zeros() unnecessary? i am in the early learning stage so your reply wd help me much
dn _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
On Dec 21, 2007 12:37 AM, devnew@gmail.com <devnew@gmail.com> wrote:
hi i am a beginner with numpy and python,so pardon me if this doubt seems silly i want to create a matrix with say 3 rows and 5 columns..and then set the values of each item in it .for this i did something like below
myarray=zeros((3,5)) #then set the items for row in range(3): for col in range(5): myarray[row][col]=999999.9999
In [1]: a = zeros([3,5]) In [2]: a[...] = 999 In [3]: a[0:2,0:2] = 99 In [4]: a Out[4]: array([[ 99., 99., 999., 999., 999.], [ 99., 99., 999., 999., 999.], [ 999., 999., 999., 999., 999.]]) Chuck
participants (3)
-
Charles R Harris -
devnew@gmail.com -
lorenzo bolla