0

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.

4

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]
| improve this answer | |
  • 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.