Home > Net >  Splitting 3d array in numpy to make smaller equal 3d array
Splitting 3d array in numpy to make smaller equal 3d array

Time:12-15

I have an array shape =(64, 64,64) I want to divide it in 8 blocks like the image, each array shape would be then (32,32,32). How do I achieve this?

octant box splitting

CodePudding user response:

You might reshape your array as follows:

import numpy as np
a = np.random.randn(64, 64, 64)
b = a.reshape((-1, 32, 32, 32))

You'll then see b.shape being equal to (8, 32, 32, 32).

CodePudding user response:

Check out numpy´s slicing:

import numpy as np

x = np.random.rand(64,64,64)

x_block_1 = x[32:64,32:64,32:64]
x_block_2 = x[0:32,32:64,32:64]
...
x_block_2 = x[32:64,0:32,0:32]

This is according to your definition.

  • Related