473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

numarray + cPickle problem

Hello all,

I've pickled a numarray array object using cPickle like so:

pickle = cPickle.Pickler(fout, -1)
pickle.dump((myarray, list1, list2))

and this seems to work fine, until I try to load the array back into
memory:

up = cPickle.Unpickler(fin)
myarray, list1, list2 = up.load()

which causes an odd traceback:

Traceback (most recent call last):
File "do_lsi.py", line 7, in ?
data, artists, users = up.load()
ImportError: No module named generic

To which I say, huh? There is indeed a numarray.generic module - but
numarray is already included into this file. I tried including
numarray.generic, or "from numarray import generic" or "from
numarray.generic import *", but none of those did anything.

Anybody able to guess what is happeneing here? Anybody that can explain
the unpickling process in greater detail for me so that I may
understand it better?

Peace
Bill Mill
bill.mill at gmail.com

Jul 18 '05 #1
5 2015
A couple more details:

I'm using Python 2.3.4 and numarray 1.1. I've now found the
numarray.array_persist module, which will let me pickle numarrays an
alternative way, but I'd still like to know what's going on here. I can
definitely pickle numarray.array objects in trivial cases.

Why doesn't Python raise an Unpickleable error? Why is it trying to
import generic?

Jul 18 '05 #2
Ok, sorry for sending another message to the list so soon, but I think
I've figured out the problem. On Windows, if you want to use one of the
binary pickle settings, you *need* to open your output file in binary
mode. Perhaps this should be mentioned in the cPickle documentation?
Peace
Bill Mill
bill.mill at gmail.com

Jul 18 '05 #3
On 13 Nov 2004 09:30:31 -0800, "Bill Mill" <bi*******@gmail.com>
wrote:
Perhaps this should be mentioned in the cPickle documentation?


It *IS* documented...

Pickler(...)
Pickler(file, proto=0) -- Create a pickler.

This takes a file-like object for writing a pickle
data stream.
The optional proto argument tells the pickler to
use the given protocol; supported protocols are 0,
1, 2. The default protocol is 0, to be backwards
compatible. (Protocol 0 is the only protocol that
can be written to a file opened in text mode and
--> read back successfully. When using a protocol
--> higher than 0, make sure the file is opened in
--> binary mode, both when pickling and unpickling.)

...

Andrea
Jul 18 '05 #4
Andrea,
It *IS* documented...


I saw that when I figured out what was going on. I should have been
more specific. What I meant was that in the Python module documentation
(of cPickle or pickle) on the web should include that little tidbit
which is really rather important. I don't believe that you need to use
binary mode on Unix (though I could be wrong), and that is where I am
used to working, so this error surprised me.

On the website, it doesn't say that anywhere, and it should, IMHO.
Peace
Bill Mill
bill.mill at gmail.com

Jul 18 '05 #5
On Sat, Nov 13, 2004 at 09:27:02AM -0800, Bill Mill wrote:
A couple more details:

I'm using Python 2.3.4 and numarray 1.1. I've now found the
numarray.array_persist module, which will let me pickle numarrays an
alternative way, but I'd still like to know what's going on here. I can
definitely pickle numarray.array objects in trivial cases.

Why doesn't Python raise an Unpickleable error? Why is it trying to
import generic?

Just a guess: the generic submodule is a C language module that doesn't
know that it's meant to be a submodule. -> So it believes it's just
"generic.numarray" and not correctly "numpy.generic.numarray".

Andreas
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out...
3
by: Alexander Schwaigkofler | last post by:
Hi! I have the following problem with numarray. I read the install.txt manual, but it doesn't already work. OS: Microsoft Windows 2000 python: Python 2.2.3 (#42, May 30 2003, 18:12:08) on...
0
by: Richard Kessler | last post by:
I am attempting a GUI using BOA Constructor. I have some simple code to pickle an object, but for some reason when I use cPickle it hangs the system, but pickle works just fine. I do not have a...
2
by: Marc Schellens | last post by:
Following the NumPy documentation, I took over some C code, but run into an error. Does anybody have a suggestion? Thanks, marc gdlpython.cpp:225: `PyArray_Type' undeclared (first use this...
3
by: SunX | last post by:
I tried to initialize a float point array by: import numarray xur = numarray.fromfunction(lambda x,y,z:x*y*z, (2, 2, 2)) but I ended up with an integer array even though x, y, and z are all...
3
by: Chris Curvey | last post by:
Hi all, I have this program class Company: def __init__(self, revenues, costs): self.revenues = revenues self.costs = costs def __getattr__(self, name):
1
by: A.B., Khalid | last post by:
I wonder if someone can explain what is wrong here. I am pickling a list of dictionaries (see code attached) and unpickling it back using the HIGHEST_PROTOCOL of pickle and cPickle. I am getting an...
4
by: Mingus Tsai | last post by:
Hello- please help with unpickling problem: I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows XPhome system. My problem is with using cPickle to deserialize my pickled...
1
by: Carl J. Van Arsdall | last post by:
Hey everyone, cPickle is raising an ImportError that I just don't quite understand. Before I paste the code, let me explain the application. Basically the part of the application that failed is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.