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?

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________

------------------------------------------------------------------------------
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

Reply via email to