I'm sure this is pretty basic, but is there a way to print a certain indexed portion of each segment in an array? For example, if I have the numpy array:

([1,2,3], [4,5,6], [7,8,9])

I'd like to print out 3,6,9.

closed as off-topic by PolyGeo, Alexandre Neto, Paul, Chad Cooper, user2856 Jun 17 '14 at 0:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development are off-topic here unless they relate directly to Geographical Information Systems, but they can be asked on Stack Overflow." – PolyGeo, Alexandre Neto, Paul, Chad Cooper, user2856
If this question can be reworded to fit the rules in the help center, please edit the question.


Access the last element using [-1] indexing.

x = numpy.array([[1,2,3], [4,5,6], [7,8,9]])
for i in x:
    print i[-1]
  • But that would just give me 7,8,9 right? I'm looking for 3,6,9. – Scott Jun 16 '14 at 21:56
  • No, the i[-1] simply gets the last element in a list. The for loop goes through each list in the array. – Dr.Ew Jun 16 '14 at 22:01
  • Oh I see. I can't believe I overlooked that. Thanks. – Scott Jun 16 '14 at 22:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.