stratusshow
stratusshow

Reputation: 25

How do I fix this MemoryError for a large array

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.

Upvotes: 0

Views: 2430

Answers (1)

Mehdi Hamzezadeh
Mehdi Hamzezadeh

Reputation: 370

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.

Upvotes: 1

Related Questions