I have three arrays (x,y,z).  I want plot x vs y and draw the line segments 
differently depending on whether or not z is positive or negative.  So I'm 
trying to split the x,y arrays into chunks depending on the value of z.  Using 
numpy.where, I can find the indeces in z that satisfy a condition but I can't 
figure out an efficient way (other than brute force) to split the array up into 
continuous chunks.  Does anyone know of a numpy trick that would help with this?

Here's a simple example:

# index:    0  1  2  3   4  5  6  7 8 9
z=numpy.array([-1,-1,-1, 1, -1,-1,-1, 1,1,1] )
x=numpy.array([-2,-3,-4, 2, -5,-6,-7, 3,4,5] )

# Want: xneg = [ x[0:3], x[4:7] ], xpos = [ x[3:4], x[7:10] ]
xneg = [ [-2,-3,-4], [-5,-6,-7] ]
xpos = [ [ 2 ], [ 3, 4, 5 ] ]

idxneg = numpy.where( z < 0 )[0]
# == [ 0,1,2, 4,5,6 ]
idxpos = numpy.where( z >= 0 )[0]
# == [ 3, 7,8,9 ]

Thanks,
Ted
------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to