473,785 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

numarray + cPickle problem

Hello all,

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

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

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

up = cPickle.Unpickl er(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.generi c module - but
numarray is already included into this file. I tried including
numarray.generi c, or "from numarray import generic" or "from
numarray.generi c 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 2033
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*******@gmai l.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.numarr ay" 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
2991
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 "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google. py2exe output is last.
3
1831
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 win32 numarray: Version 0.7 the output from the installation (by hand) you can see below:
0
1197
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 clue why cPickle will not work. The code is myObj = MyObject() myObj.SetSomeProperties f = open("my file name",'w')
2
2970
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 function) #include <python2.3/Python.h>
3
1600
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 floats. BTW, how do you unzip NumTut in windows? And is there a newer version? Thank you
3
1812
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
3508
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 error message and trace backs if the list exceeds eight items. Whether I use pickle or cPickle does not matter, i.e., the eight number causes a problem in both modules, although the trace backs are of course dissimilar. This pickling and...
4
2833
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 arrays of datetime.datetime instances. The following is the code I have written: import cPickle, datetime import Numeric
1
1373
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 function that loads a list of objects from a file using cPickle. This list is a queue of requests. I've done some research and it looks like cPickle tries to load some modules as some kind of test. From what I can tell the module that cPickle...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.