Alan W. Irwin wrote: > On 2009-04-08 19:33-0400 Hazen Babcock wrote: > >> Hello, >> >> Apologies if this has already been reported... >> >> While using Numpy and PLplot I've stumbled over a potential problem with >> the interface. Numpy arrays are not necessarily contiguous in memory, >> i.e. if I have a 2D array: >> >> p = [[1,2],[2,3],[3,4]] >> >> And I do: >> plplot.plpoin(p[:,0], p[:,1], 9) >> >> Then I'll get a segmentation fault. Surprisingly, I have found that even >> some 1D arrays are not be contiguous. Should we be trying to protect the >> user by doing something like this to all the arrays that we get from numpy? >> plplot.plpoin(numpy.ascontiguousarray(p[:,0]), >> numpy.ascontiguousarray(p[:,1]), 9) > > Your report got me curious since I use plenty of two dimensional array > in python/numpy without problems. So I just now tried the following: > >>>> from numpy import * >>>> p = [[1,2],[2,3],[3,4]] >>>> p > [[1, 2], [2, 3], [3, 4]] >>>> p[:,0] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: list indices must be integers > > However, if you put an array around it all is well. > >>>> p = array(p) >>>> p > array([[1, 2], > [2, 3], > [3, 4]]) >>>> p[:,0] > array([1, 2, 3]) >>>> p[:,1] > array([2, 3, 4]) > > I haven't tried it, but I am virtually positive array([1, 2, 3]) and > array([2, 3, 4]) would work fine as arguments to plpoin. > > Thus, is the problem that you forgot to turn the ordinary two-dimensional > python array into a numpy one (with array) before you tried to create > one-dimensional array results from two-dimensional ones?
When I ran into this issue I was using numpy arrays that I'd have saved (and then reloaded) using Pytables. For some reason when I used slices of these array in the call to plploin I would get a segfault, but if I created an intermediate variable that stored a contiguous version of each slice of interest from the array then everything was fine. I just assumed that this was a numpy / plplot issue, but now in trying to write a test case without using pytables I don't see any problem. This works as expected for me either way: import numpy import plplot plplot.plsdev("xcairo") plplot.plspage(72, 72, 800, 800, 0, 0) plplot.plinit() plplot.plenv(0.0, 2.0, 0.0, 2.0, 0, 0) for i in range(1000): objs = numpy.random.random((200,6)) objs[:,2] += 1.0 if 0: x = numpy.ascontiguousarray(objs[:,1]) y = numpy.ascontiguousarray(objs[:,2]) plplot.plpoin(x, y, 1) else: plplot.plpoin(objs[:,1], objs[:,2], 1) plplot.pllab("X", "Y", "Spot Locations") plplot.plend() So it must be something unusual about arrays that have been stored and reloaded using pytables. -Hazen ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel