views:

227

answers:

1

Good day coders and codereses,

I am writing a piece of code that goes through a pile of statistical data and returns what I ask from it. To complete its task the method reads from one multidimensional array and writes into another one. The piece of code giving me problems is:

writer.variables[variable][:, :, :, :] = reader.variables[variable][offset:, 0, 0:5, 3]

The size of both slices is 27:1:6:1 but it throws up an exception:

ValueError: total size of new array must be unchanged

I am flabbergasted.

Thank you.

+1  A: 

The size of a slice with 0:5 is not 6 as you say: it's 5. The upper limit is excluded in slicing (as it most always is, in Python). Don't know whether that's your actual problem or just a typo in your question...

Alex Martelli
Oh wow. I've spent an hour trying to debug this just because I have perceived the bug being of enormous complexity. Thank you sir.
Rince
@Rince, you're welcome!
Alex Martelli