Well, your array a already takes 1192953*192*32* 8 bytes/1.e9 = 58 GB memory.
Translation does not create additional memory allocations for the initial arrays, but the result
b[:, :, np.newaxis] - c[np.newaxis, :, :]
stored in a temporary array. Therefore, in this line you have allocated at least 2 arrays with the form a for the total used memory >116 GB .
You can avoid this problem by working with a smaller subset of your array at a time,
CHUNK_SIZE = 100000 for idx in range(b.shape[0]/CHUNK_SIZE): sl = slice(idx*CHUNK_SIZE, (idx+1)*CHUNK_SIZE) a[sl] = b[sl, :, np.newaxis] - c[np.newaxis, :, :]
it will be a little slower, but uses much less memory.
rth
source share