问题描述
我有 8823 个带有 x、y 坐标的数据点.我正在尝试遵循关于 如何获得的答案一个散点数据集表示为热图 但是当我通过
I have 8823 data points with x,y coordinates. I'm trying to follow the answer on how to get a scatter dataset to be represented as a heatmap but when I go through the
X, Y = np.meshgrid(x, y)
关于我的数据数组的指令,我得到 MemoryError
.我是 numpy 和 matplotlib 的新手,我基本上是在尝试通过调整我能找到的例子来运行它.
instruction with my data arrays I get MemoryError
. I am new to numpy and matplotlib and am essentially trying to run this by adapting the examples I can find.
以下是我从存储数组的文件构建数组的方法:
Here's how I built my arrays from a file that has them stored:
XY_File = open ('XY_Output.txt', 'r')
XY = XY_File.readlines()
XY_File.close()
Xf=[]
Yf=[]
for line in XY:
Xf.append(float(line.split('\t')[0]))
Yf.append(float(line.split('\t')[1]))
x=array(Xf)
y=array(Yf)
我的阵列有问题吗?当放入 这个例子 时,同样的代码有效,但我不太确定.
Is there a problem with my arrays? This same code worked when put into this example but I'm not too sure.
为什么我会收到此 MemoryError 以及如何解决此问题?
Why am I getting this MemoryError and how can I fix this?
推荐答案
您对 meshgrid
的调用需要大量内存——它产生两个 8823*8823 的浮点数组.每个大约 0.6 GB.
Your call to meshgrid
requires a lot of memory -- it produces two 8823*8823 floating point arrays. Each of them are about 0.6 GB.
但是无论如何您的屏幕都无法显示(并且您的眼睛无法真正处理)那么多信息,因此在执行此步骤之前,您可能应该想办法将数据平滑为更合理的值,例如 1024*1024.
But your screen can't show (and your eye can't really process) that much information anyway, so you should probably think of a way to smooth your data to something more reasonable like 1024*1024 before you do this step.
这篇关于运行 Numpy Meshgrid 时出现内存错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!