On Thu, 2008-06-19 at 02:30 +0200, [EMAIL PROTECTED] wrote:
> Message: 2
> Date: Wed, 18 Jun 2008 19:43:21 +0530
> From: "amit sethi" <[EMAIL PROTECTED]>
> Subject: [Tutor] (no subject)
> To: tutor@python.org
> Message-ID:
>         <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Hi , Could you please tell me , how i can traverse a two dimensional
>>> from numpy import * # import the necessary module

> >>> arry = array((1,2,3,4)) # create a rank-one array
> >>> print arry
> [1 2 3 4]
> >>> print arry.shape
> (4,) # this means it is a rank 1 array with a length of 4  (the trailing 
> comma means it is a tuple)
> 
> To get to the first element in the array:
>  print arry[0]
> 1
> 
> To get to the last element:
> >>> print arry[-1]
> 4
> >>> 
>  
> >>> arry2 = array(([5,6,7,8],[9,10,11,12])) # create a a rank-two array, 
> >>> two-dimensional, if wish
> >>> print arry2
> [[ 5  6  7  8]
>  [ 9 10 11 12]]
> >>> print arry2.shape #
> (2, 4) # this means that it is a rank 2 (ie 2-dimensional) array, with each 
> axis having a length of 4
> >>> 
> To get to the first element in the first axis:
> >>> print arry2[0,0]
> 5
> To get to the last element in the second axis:
> >>> print arry2[1,-1]
> 12
> 
> Does this help?
> Kinuthia...



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to