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

J_yang
  • 2,672
  • 8
  • 32
  • 61

1 Answers1

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.

Uri Granta
  • 1,814
  • 14
  • 25