I once saw the following code segment, and am not clear what it does really do?
d = np.mean(a[::b,:,c:-c], axis=2, keepdims=False)
In specifi, what ::b
means here?
I once saw the following code segment, and am not clear what it does really do?
d = np.mean(a[::b,:,c:-c], axis=2, keepdims=False)
In specifi, what ::b
means here?
'::b' means "skip by b elements", (e.g. if 'b' = 3, this will give every third element in the list).
"Extended Slices" is the category of what you are asking about. Good luck!
Python use slicing to specify how to slice a sequence. You can specify where to start the slicing, and where to end. You can also specify the step. step also refer to as interval here.
Syntax : a[start:end:step]
Example :
y = np.arange(42).reshape(6,7)
y[0::2]
Here 0 is the lower limit and 2 is the interval. The output will start at index 0 and keep going till the end with an interval of 2. That means every second row. This how our output will look like
Output:
array([[ 0, 1, 2, 3, 4, 5, 6],
[14, 15, 16, 17, 18, 19, 20],
[28, 29, 30, 31, 32, 33, 34]])