Index, slice

x = np.array([1, 2, 3, 4, 5, 6, 7, 8])
print(x[2]) # 3
means return a single value
x = np.array([1, 2, 3, 4, 5, 6, 7, 8])
print(x[1:5:2])
Does this represent a value with an interval of 2 between index 1 and 5? Close left and open right

Two-dimensional array slice:
x = np.array([[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25],
[26 , 27, 28, 29, 30],
[31, 32, 33, 34, 35]])
print(x[0:2]) means output one or two lines
print(x[-2:]) means output reverse Count one or two lines

[[26 27 28 29 30]

[31 32 33 34 35]]

x[0::2, 1::3] = 0 I don’t understand
print(x) here

[[11 0 13 14 0]

[16 17 18 19 20]

[21 0 23 24 0]

[26 27 28 29 30]

[31 0 33 34 0]]

Guess you like

Origin blog.csdn.net/m0_49978528/article/details/109250585