0

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?

user297850
  • 7,705
  • 17
  • 54
  • 76

2 Answers2

1

'::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!

BLimitless
  • 2,060
  • 5
  • 17
  • 32
1

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]])