newbie doubt ..numpy array

N

nodrogbrown

if this is too silly a qn pls forgive
I was learning numpy.ndarrays thru the tutorial.

myarr=numpy.array( [ [10, 20, 30, 40],[1,2,3,4],[5,6,7,8] ] )
if i want to access the element 3 i can do it by myarr[1, 2]

but then myarr[1][2] will also give the same result..is there any
reason why two types of indexing is allowed?
gordon

p.s(i tried to post to numpy grp but it is not appearing there!)
 
D

Dennis Lee Bieber

myarr=numpy.array( [ [10, 20, 30, 40],[1,2,3,4],[5,6,7,8] ] )
if i want to access the element 3 i can do it by myarr[1, 2]

but then myarr[1][2] will also give the same result..is there any
reason why two types of indexing is allowed?
gordon
The first is likely a numpy extension (and corresponds to the syntax
many of the classical number crunching languages support: FORTRAN,
Ada...). The second is Python's native syntax (and corresponds to less
focused languages -- such as C; in which a matrix [2D array] is an array
of arrays). You first retrieve the sublist accessed by [1], and then
access the element addressed by [2]
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top