-1

I understand the basic idea behind the : operator like:

A[:] Returns the entire array
A[::-1] Returns the array in reverse.

But suppose iris.data is a n X 4 matrix, what does this do?

X = iris.data[:, (2,3)]
Ace
  • 1,501
  • 4
  • 30
  • 49
  • 1
    get all rows, columns 2 and 3 – rafaelc Sep 24 '18 at 14:19
  • What is `iris`' type? Is it something from numpy? – Kevin Sep 24 '18 at 14:21
  • 1
    `:` isn't an operator; it's just syntax for specifying a slice object. `A[:]` becomes `A[slice(None, None, None)]`; `A[::-1]` becomes `A[slice(None, None, -1)]`; `A[:, (2,3)]`is `A[(slice(None, None, None), (2,3))]` (that is, they key is a tuple consisting of a `slice` object and another tuple). In any case, it's the class's `__getitem__` method that determines what is actually *done* with the resulting key. – chepner Sep 24 '18 at 14:25

1 Answers1

1

It will get you the second and third column from all rows.

Here you can find some more information: python-slicing-a-multi-dimensional-array and Understanding Python's slice notation

Sharku
  • 1,052
  • 1
  • 11
  • 24