Rich Shepard <rshepard@...83...> writes:
x,y = [(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)]
ValueError: too many values to unpack
You are looking for the classic "unzip" trick:
x,y = zip(*[(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)])
···
--
Jouni
Jouni,
That's totally new to me. I'll go find out what it is and how it works its
magic.
Thank you,
Rich
···
On Sun, 25 Nov 2007, Jouni K Seppänen wrote:
You are looking for the classic "unzip" trick:
x,y = zip(*[(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)])
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
Jouni,
Thank you for pointing this out to me. I see that it's a builtin function
similar to map that assembles the first element of each tuple into a list
for the first variable, and the second element of each tuple into a list for
the second variable. How useful for my plotting needs!
Rich
···
On Sun, 25 Nov 2007, Jouni K Seppänen wrote:
x,y = zip(*[(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)])
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
Rich Shepard wrote:
x,y = zip(*[(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)])
or better yet -- work with numpy arrays from the beginning:
Either put x an y into separate arrays (which is what MPL expects), or if you like X and Y begin together (I do):
points = numpy.array([(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)])
x = points[:,0]
y = points[:,1]
and:
p0 = points[0]
p1 = points[1]
etc. etc.
-Chris
···
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@...259...
Chris,
These values are retrieved from widgets on a notebook page and the plot
will be used to display them on that tab. It would take more code to
convert those values to a numpy array.
Rich
···
On Mon, 26 Nov 2007, Christopher Barker wrote:
or better yet -- work with numpy arrays from the beginning:
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863