3

I want to replace the column slicing of a Numpy Array by a variable. e.g.

a = np.zeros((3, 3))
slic = 3
a[:, slic]

So how do I represent : case where:

a[:, slic] == a[:, :]

so what should slic = ?

Many thanks

J

1
  • slice(None) This a standard python obhect class. Commented Oct 12, 2019 at 12:11

1 Answer 1

2

As mentioned in the comment, the colon notation inside brackets generates an internal slice(start, end, step) object. Your specific slic should therefore be set to slice(None). See here for details.

Note that numpy slices can generally be an integer, a slice object, an Ellipsis, a newaxis, or a tuple of the above. You could therefore also assign slic to the tuple (slice(None), slice(None)) and pass that in instead. See here for numpy details.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.