[Numpy-discussion] setting items in a matrix
Charles R Harris
charlesr.harris at gmail.com
Fri Dec 21 12:01:49 EST 2007
On Dec 21, 2007 12:37 AM, devnew at gmail.com <devnew at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20071221/c6e0da0e/attachment.html>
More information about the NumPy-Discussion
mailing list