0

I am getting this error in my code: MemoryError: Unable to allocate 10.5 GiB for an array with shape (61, 17, 41, 59, 51, 11) and data type float64 When I try to run my code at

#Control test to look at 4-Seamer at different approaches
import numpy as np
import math
#Creating the Arrays for the baseball pitch (Testing 4-Seam FB)
phi=np.linspace(175,180,61)*math.pi/180.0
theta=np.linspace(-4,4,17)*math.pi/180.0
speed=np.linspace(90,100,41)
tilt=np.linspace(190,235,59)*math.pi/180.0
RPM=np.linspace(2050,2350,51)
gyro=np.linspace(0,10,11)*math.pi/180.0
#Weather Conditions (Control shown here for TB's Tropicana Dome)
tf=72.0
tc=(tf-32)*5/9
tk=tc+273.15
press=1013.15
ppa=press*100.0
RH=0.55
rho=ppa/(287*tk)
tau=500
dt=0.0001
#Release Points
x0=-2.5
y0=55.0
z0=6.0
backtopspin=np.empty(((61),(17),(41),(59),(51),(11)))
sidespin=np.empty(np.shape(backtopspin))

I am trying to develop this code so I can look at how just the slightest change in any of the angles and speed and spin will affect the movement. T

Thanks.

5
  • How much RAM does your machine have? Commented Jan 27, 2021 at 20:26
  • 8 GB with 7.88 GB usable. Commented Jan 27, 2021 at 20:28
  • That's just how much memory that object takes up. You don't have that much available on your computer. You can't allocate the object. You can either manually break up the problem into smaller parts or you can use tools like Dask that are designed for out-of-core computing. Commented Jan 27, 2021 at 20:32
  • you could use a cloud compute resource like those supplied by AWS/GCP rent it by the hour and have more RAM than your PC Commented Jan 27, 2021 at 20:34
  • Is there a better way for me to have the arrays as I want to expand my research into the future without having to manually input every single detail every time I run. Commented Jan 27, 2021 at 20:38

1 Answer 1

1

the problem is that your memory usage exceeds your available memory. you should try to optimize your memory usage. for example the default data type for np.array is float64. you can save lot of memory with changing your code to

backtopspin=np.empty(((61),(17),(41),(59),(51),(11)), dtype=np.float32)
sidespin=np.empty(np.shape(backtopspin), dtype=np.float32)

here you can read more about python data types to select the one which suits your needs the best.

if even that is not enough try using less samples and lowering your array dimensions.

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

Comments

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.