Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

python - Slicing a 3D numpy array using on a fixed window and stride

I'm trying to learn how to work with image data in numpy arrays. Currently I have a single array with 4 channels where the shape is (221, 95, 4).

I'm trying to subdivide this array into smaller arrays with a fixed window size, and using a window stride, to get a new shape of (n, 20, 20, 4).

So far I have this, but am getting confused:

step = 20
win_size = 10

#stacked is a 3D array
x_steps = (stacked.shape[0]-win_size)//step
y_steps = (stacked.shape[0]-win_size)//step
print(x_steps)
print(y_steps)
tiles = []

for i in range(x_steps): 
  mini = stacked[i*step : i*step+win_size, i*step : i*step+win_size ,:]
  tiles.append(mini)

tiles = np.array(tiles)

I think I'm close, but how do I take into account both the x and y direction of the window?

question from:https://stackoverflow.com/questions/65864922/slicing-a-3d-numpy-array-using-on-a-fixed-window-and-stride

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...