4

I have a array of size 13000*300000 filled with integer from 0 to 255. I would like to change their data type from integer to float as if data is a numpy array:

 data.astype('float')

While changing its data type from integer to float, it shows memory error. I have 80 GB of RAM. It still shows memory error. Could you please let me know what can be the reason for it?

3
  • possible duplicate of How do I profile memory usage in Python? Commented Apr 5, 2014 at 0:48
  • 1
    your data is about 30 GB located sequentially in memory. You need more 30 GB (also sequentially) to store the result. I believe key point here is sequentially Commented Apr 5, 2014 at 0:56
  • Its true data is in sequence. Commented Apr 5, 2014 at 1:00

1 Answer 1

9

The problem here is that data is huge (about 30GB of sequential data, see How much memory in numpy array?), hence it causes the error while trying to fit it into the memory. Instead of doing the operation on whole, slice it and then do the operation and then merge, like:

n = 300000
d1 = data[:, :n/2].astype('float')
d2 = data[:, n/2:].astype('float')

data = np.hstack(d1, d2)

Generally, since your data size is so unwieldy, consider consuming it in parts to avoid being bitten by these sorts of problems all the time (see Techniques for working with large Numpy arrays? for this and other techniques).

Sign up to request clarification or add additional context in comments.

1 Comment

it is very likely that you'll have to del data before hstack in order to free enough memory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.