[Numpy-discussion] Re: weird interaction: pickle, numpy, matplotlib.hist [sort() method problem?]

Andrew Jaffe a.h.jaffe at gmail.com
Wed Apr 5 08:48:27 EDT 2006


OK, I think I've managed to track the problem down a bit further:

    the sort() method is failing for arrays pickled on another machine!

That is, it's definitely not sorting the array, but changing to a very
strange order (neither the way it started nor sorted).

Again, the array seems to otherwise behave fine (indeed, it even satisfies
all(a==a1) for a pair that behave differently in this circumstance).

Hmmm...

A


On 4/5/06, Andrew Jaffe <a.h.jaffe at gmail.com> wrote:
>
> Hi All,
>
> I've encountered a strange problem: I've been running some python code
> on both a linux box and OS X, both with python 2.4.1 and the latest
> numpy and matplotlib from svn.
>
> I have found that when I transfer pickled numpy arrays from one machine
> to the other (in either direction), the resulting data *looks* all right
> (i.e., it is a numpy array of the correct type with the correct values
> at the correct indices), but it seems to produce the wrong result in (at
> least) one circumstance: matplotlib.hist() gives the completely wrong
> picture (and set of bins).
>
> This can be ameliorated by running the array through
>     arr=numpy.asarray(arr, dtype=numpy.float64)
> but this seems like a complete kludge (and is only needed when you do
> the transfer between machines).
>
> I've attached a minimal code that exhibits the problem: try
>         test_pickle_hist.test(write=True)
> on one machine, transfer the output file to another machine, and run
>         test_pickle_hist.test(write=False)
> on another, and you should see a very strange result (and it should be
> fixed if you set asarray=True).
>
> Any ideas?
>
> Andrew
>
>
> import cPickle
> import numpy
> import pylab
>
> def test(write=True,asarray=False):
>
>     a = numpy.linspace(-3,3,num=100)
>
>     if write:
>         f1 = file("a.cpkl", 'w')
>         cPickle.dump(a, f1)
>         f1.close()
>
>     f1 = open("a.cpkl", 'r')
>     a1 = cPickle.load(f1)
>     f1.close()
>
>     pylab.subplot(1,2,1)
>     h = pylab.hist(a)
>
>     if asarray:
>         a1 = numpy.asarray(a1, dtype=numpy.float64)
>
>     pylab.subplot(1,2,2)
>     h1 = pylab.hist(a1)
>
>     return a, a1
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060405/7fd0ad2a/attachment.html>


More information about the NumPy-Discussion mailing list