使用numpy错误在python中进行内存映射 [英] memory-mapping in python using numpy error

查看:126
本文介绍了使用numpy错误在python中进行内存映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OUT_DIR = '/media/sf_3dAnalysis/simMatrix/'  
SIM_FILE = 'similarity.npy'

data = np.lib.format.open_memmap(OUT_DIR+SIM_FILE, mode='w+', dtype='float32', shape=(len(filelist),len(filelist)))
del data

所以我在运行此代码时收到以下错误消息... mmap.error: [Errno 22] Invalid argument.我真的不明白我在做什么错.如果相关的话,我正在Linux VM中运行它.另外,特别奇怪的是,矩阵在代码运行后创建,但是仍然崩溃,表明参数无效,这对于为什么说参数无效时为什么要创建矩阵却毫无意义.

So I get the following error message when running this code... mmap.error: [Errno 22] Invalid argument. I really don't understand what I am doing wrong. I am running this in a Linux VM if that's relevant. Also, what's particularly curious is the matrix is created after the code runs, but it still crashes saying the argument is invalid which makes no sense as to why it would be creating the matrix when it says the argument is invalid.

我需要做些特殊的事情来使内存映射在Linux机器上与Windows和Mac一起工作吗?因为它在我的Mac和Windows机器上都能正常工作.我想我应该指定更多,在虚拟机中是否需要设置某些设置或某些设置才能使内存映射正常工作?因为我在正常运行Linux的计算机上进行了尝试,所以它可以正常工作.

Is there anything special I need to do to get memory mapping to work on a linux machine versus windows and mac? Because it is working fine on my mac and windows machine. I guess I should specify even more, is there some setting or something that needs to be set-up in a virtual machine to have memory mapping working? Because I tried it on a computer running Linux normally, and it worked.

推荐答案

所以我解决了我的问题专家.我在虚拟机上创建了矩阵的本地副本.然后,我将该副本移至共享文件夹.这是说明这一点的代码.

So I fixed my problem guys. I created a local copy of the matrix on the Virtual Machine. I then moved that copy to a shared folder. Here is the code illustrating that.

#create local copy
data = np.memmap(SIM_FILE, dtype='float32', mode='w+', 
          shape=(len(filelist),len(filelist)))
#move local copy to shared folder
os.system('mv' + " ~/Desktop/" + SIM_FILE + " " + OUT_DIR ) 

这篇关于使用numpy错误在python中进行内存映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆