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
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
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.