I have a very big 6D array as (225, 97, 225, 32, 32, 32)
. I want to reshape it into 4D array like (225*97*225, 32, 32, 32)
. I tried to used python 2.7 in ubuntu 14.04 with bellow code but I got the memory error. How could I solve it? Thanks
import numpy as np
#input_6D shape (225, 97, 225, 32, 32, 32)
input_4D= input_6D.reshape(input_6D.shape[0]*input_6D.shape[1]*input_6D.shape[2], input_6D[0],input_6D[1],input_6D[2])
The error is
input_4D= input_6D.reshape(input_6D.shape[0]*input_6D.shape[1]*input_6D.shape[2], input_6D[0],input_6D[1],input_6D[2]) MemoryError
This is step what I did. First, I load a 3D input with shape 256x128x256
. Then I used the code bellow to got 6D array as (225, 97, 225, 32, 32, 32)
where patch shape is 32, 32, 32
def patch_extract_3D(input,patch_shape):
patches_6D = np.lib.stride_tricks.as_strided(input, ((input.shape[0] - patch_shape[0] + 1) // xstep, (input.shape[1] - patch_shape[1] + 1) // ystep,
(input.shape[2] - patch_shape[2] + 1) // zstep, patch_shape[0], patch_shape[1], patch_shape[2]),
(input.strides[0] * xstep, input.strides[1] * ystep,input.strides[2] * zstep, input.strides[0], input.strides[1],input.strides[2]))