gpt4 book ai didi

python - 绕过 "Array is too big"python 错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:57:55 25 4
gpt4 key购买 nike

我有一个包含超过 200 000 行气象数据的 csv 文件。当我想用matplotlib对数据进行建模时,出现了这个错误:

Traceback (most recent call last):
File "try4.py", line 19, in <module>
X,Y = meshgrid( data_x,data_y )
File "C:\Python27\lib\site-packages\numpy\lib\function_base.py", line 3378, in meshgrid
mult_fact = np.ones(shape, dtype=int)
File "C:\Python27\lib\site-packages\numpy\core\numeric.py", line 148, in ones
a = empty(shape, dtype, order)
ValueError: array is too big.

我发现最多可以处理 5000 行的文件。如何绕过错误以处理所有 200000 行的文件?这是我的代码:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from pylab import *


# read CSV as a numpy array
data = mlab.csv2rec('datasets/mix.csv')

# print CSV file headers
print data.dtype.names

# load columns as vectors
data_x = data['longitude']
data_y = data['latitude']
data_u = data['x']
data_v = data['y']

X,Y = meshgrid( data_x,data_y )
U = cos(data_u)
V = sin(data_v)


# plot raw data
Q = quiver( X, Y, U, V, units='width')
qk = quiverkey(Q, 0.5, 0.92, 2, '.', labelpos='W',
fontproperties={'weight': 'bold'})
title('Current Surface')

plt.show()

最佳答案

为什么您使用 meshgrid ( doc )?它会很好地生成一个 200k x 200k 的数组,该数组将与您的 uv 数据的尺寸不匹配。我想你想这样做

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from pylab import *


# read CSV as a numpy array
data = mlab.csv2rec('datasets/mix.csv')

# print CSV file headers
print data.dtype.names

# load columns as vectors
data_x = data['longitude']
data_y = data['latitude']
data_u = data['x']
data_v = data['y']

U = cos(data_u)
V = sin(data_v)


# plot raw data
Q = quiver(data_x, data_y, U, V, units='width')
qk = quiverkey(Q, 0.5, 0.92, 2, '.', labelpos='W',
fontproperties={'weight': 'bold'})
title('Current Surface')

关于python - 绕过 "Array is too big"python 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17314689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com