From: Michael Droettboom <mdroe@st...>  20120606 16:50:07

On 06/06/2012 12:42 PM, Ethan Gutmann wrote: >> ... >> No, but you can do this: >> >> plt.plot([3] * 4, [60, 80, 120, 180], ...) > Using int16, int32, float32 get progressively slower to the default float64 case listed on line [5], changing the datatype in other methods doesn't result in nearly as large a speed up as it does in the last case. > Interesting result. Note, however, that matplotlib will eventually turn all data arrays into float64 at rendering time, so any speed advantage to using integers will be lost by the subsequent conversion, I suspect. Mike 
From: Ulrich vor dem Esche <ulrich.esche@go...>  20120605 15:53:50
Attachments:
Message as HTML

Hey! :o) This should be simple, but i cant manage: I need to plot many dots with the same x, like plt.plot([3,3,3,3],[60,80,120,180],'+',markersize=8,mec='k') The array for x values is silly, especially since the number of y values may be rather large. Is there a way to enter a constant there? Cheers to you all! Ulli 
From: Benjamin Root <ben.root@ou...>  20120606 16:15:16
Attachments:
Message as HTML

On Tue, Jun 5, 2012 at 11:53 AM, Ulrich vor dem Esche < ulrich.esche@...> wrote: > Hey! :o) > This should be simple, but i cant manage: I need to plot many dots with > the same x, like > > plt.plot([3,3,3,3],[60,80,120,180],'+',markersize=8,mec='k') > > The array for x values is silly, especially since the number of y values > may be rather large. Is there a way to enter a constant there? > > Cheers to you all! > Ulli > > No, but you can do this: plt.plot([3] * 4, [60, 80, 120, 180], ...) Does that help? Ben Root 
From: Ethan Gutmann <ethan.gutmann@gm...>  20120606 16:42:49

> ... > No, but you can do this: > > plt.plot([3] * 4, [60, 80, 120, 180], ...) This started from a simple enough question, but it got me thinking about what the fastest way to do this is (in case you have HUGE arrays, or many loops over them). This may be old news to some of you, but I thought it was interesting: In ipython pylab In [1]: %timeit l=[3]*10000 10000 loops, best of 3: 53.3 us per loop In [2]: %timeit l=np.zeros(10000)+3 10000 loops, best of 3: 26.9 us per loop In [3]: %timeit l=np.ones(10000)*3 10000 loops, best of 3: 32.9 us per loop In [4]: %timeit l=(np.zeros(1)+3).repeat(10000) 10000 loops, best of 3: 87.4 us per loop In [5]: %timeit l=np.zeros(10000);l[:]=3 10000 loops, best of 3: 21.6 us per loop In [6]: %timeit l=np.zeros(10000,dtype=np.uint8);l[:]=3 100000 loops, best of 3: 13.9 us per loop Using int16, int32, float32 get progressively slower to the default float64 case listed on line [5], changing the datatype in other methods doesn't result in nearly as large a speed up as it does in the last case. Ben's method is probably the most elegant for small arrays, but does any one else have a faster way to do this? (I'm assuming no use of blitz, inline C, f2py, but if you think you can do it faster in one of those, show me the way). Sorry, maybe this is more appropriate on the numpy list. Ethan 
From: Eric Firing <efiring@ha...>  20120606 17:41:35

On 06/06/2012 06:42 AM, Ethan Gutmann wrote: >> ... >> No, but you can do this: >> >> plt.plot([3] * 4, [60, 80, 120, 180], ...) > > This started from a simple enough question, but it got me thinking about what the fastest way to do this is (in case you have HUGE arrays, or many loops over them). This may be old news to some of you, but I thought it was interesting: > > In ipython pylab > > In [1]: %timeit l=[3]*10000 > 10000 loops, best of 3: 53.3 us per loop > > In [2]: %timeit l=np.zeros(10000)+3 > 10000 loops, best of 3: 26.9 us per loop > > In [3]: %timeit l=np.ones(10000)*3 > 10000 loops, best of 3: 32.9 us per loop > > In [4]: %timeit l=(np.zeros(1)+3).repeat(10000) > 10000 loops, best of 3: 87.4 us per loop > > In [5]: %timeit l=np.zeros(10000);l[:]=3 > 10000 loops, best of 3: 21.6 us per loop > > In [6]: %timeit l=np.zeros(10000,dtype=np.uint8);l[:]=3 > 100000 loops, best of 3: 13.9 us per loop > > Using int16, int32, float32 get progressively slower to the default float64 case listed on line [5], changing the datatype in other methods doesn't result in nearly as large a speed up as it does in the last case. > > Ben's method is probably the most elegant for small arrays, but does any one else have a faster way to do this? (I'm assuming no use of blitz, inline C, f2py, but if you think you can do it faster in one of those, show me the way). > Since we end up needing float64 anyway: In [3]: %timeit l=np.empty(10000,dtype=np.float64); l.fill(3) 100000 loops, best of 3: 14.1 us per loop In [4]: %timeit l=np.zeros(10000,dtype=np.float64);l[:]=3 10000 loops, best of 3: 26.6 us per loop Eric > Sorry, maybe this is more appropriate on the numpy list. > > Ethan > > >  > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers 
From: Ethan Gutmann <ethan.gutmann@gm...>  20120606 18:04:17

On Jun 6, 2012, at 11:41 AM, Eric Firing wrote: > Since we end up needing float64 anyway: > > In [3]: %timeit l=np.empty(10000,dtype=np.float64); l.fill(3) > 100000 loops, best of 3: 14.1 us per loop nice, fill and empty seem to be responsible for about half the speed up each, good tools to know about. 
From: Stan West <stan.west@nr...>  20120606 18:16:17

> From: Eric Firing [mailto:efiring@...] > Sent: Wednesday, June 06, 2012 13:41 > To: matplotlibusers@... > Subject: Re: [Matplotlibusers] scatter plot with constant x > > On 06/06/2012 06:42 AM, Ethan Gutmann wrote: > >> ... > >> No, but you can do this: > >> > >> plt.plot([3] * 4, [60, 80, 120, 180], ...) > > > > This started from a simple enough question, but it got me > thinking about what the fastest way to do this is (in case > you have HUGE arrays, or many loops over them). [...] > Since we end up needing float64 anyway: > > In [3]: %timeit l=np.empty(10000,dtype=np.float64); l.fill(3) > 100000 loops, best of 3: 14.1 us per loop > > In [4]: %timeit l=np.zeros(10000,dtype=np.float64);l[:]=3 > 10000 loops, best of 3: 26.6 us per loop > > Eric Numpy's as_strided came to mind; it can make a large array that's really a view of a oneelement array: In [1]: as_strided = np.lib.stride_tricks.as_strided In [2]: s = as_strided(np.array([3], dtype=np.float64), shape=(10000,), ...: strides=(0,)) In [3]: s[0] = 4 In [4]: s[9999] # all elements share data Out[4]: 4.0 It's somewhat slower to create the base array and the view than to create and fill a 10000element array: In [5]: %timeit l = np.empty(10000, dtype=np.float64); l.fill(3) 100000 loops, best of 3: 10.1 us per loop In [6]: %timeit s = as_strided(np.array([3], dtype=np.float64), shape=(10000,), strides=(0,)) # line broken for email 10000 loops, best of 3: 21.6 us per loop However, once created, its contents may be changed much more quickly: In [7]: l = np.empty(10000, dtype=np.float64) In [8]: %timeit l.fill(3) 100000 loops, best of 3: 7.71 us per loop In [9]: %timeit s[0] = 3 10000000 loops, best of 3: 116 ns per loop Numpy's broadcast_arrays uses as_strided under the hood. Code could look like: x, y = np.broadcast_arrays(3, [60, 80, 120, 180]) plt.plot(x, y, '+') x[0] = 21 # new x for all samples plt.plot(x, y, 'x') 
From: DP<arker@ch...>  20120622 13:08:15
Attachments:
Message as HTML

I usually do something like: y=np.array([60,80,120,180]) x = np.ones_like(y)*3 plt.plot(x, y,'+',markersize=8,mec='k') David G. Parker From: Benjamin Root <ben.root@...> To: Ulrich vor dem Esche <ulrich.esche@...> Cc: matplotlibusers@... Date: 06/06/2012 12:15 PM Subject: Re: [Matplotlibusers] scatter plot with constant x On Tue, Jun 5, 2012 at 11:53 AM, Ulrich vor dem Esche < ulrich.esche@...> wrote: Hey! :o) This should be simple, but i cant manage: I need to plot many dots with the same x, like plt.plot([3,3,3,3],[60,80,120,180],'+',markersize=8,mec='k') The array for x values is silly, especially since the number of y values may be rather large. Is there a way to enter a constant there? Cheers to you all! Ulli No, but you can do this: plt.plot([3] * 4, [60, 80, 120, 180], ...) Does that help? Ben Root  Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________ Matplotlibusers mailing list Matplotlibusers@... https://lists.sourceforge.net/lists/listinfo/matplotlibusers 
From: Michael Droettboom <mdroe@st...>  20120606 16:50:07

On 06/06/2012 12:42 PM, Ethan Gutmann wrote: >> ... >> No, but you can do this: >> >> plt.plot([3] * 4, [60, 80, 120, 180], ...) > Using int16, int32, float32 get progressively slower to the default float64 case listed on line [5], changing the datatype in other methods doesn't result in nearly as large a speed up as it does in the last case. > Interesting result. Note, however, that matplotlib will eventually turn all data arrays into float64 at rendering time, so any speed advantage to using integers will be lost by the subsequent conversion, I suspect. Mike 
From: Ethan Gutmann <ethan.gutmann@gm...>  20120606 16:55:03

On Jun 6, 2012, at 10:49 AM, Michael Droettboom wrote: > Interesting result. Note, however, that matplotlib will eventually turn > all data arrays into float64 at rendering time, so any speed advantage > to using integers will be lost by the subsequent conversion, I suspect. I don't think it does if you pass uint8 to imshow, but otherwise you might be right. ethan 
From: Michael Droettboom <mdroe@st...>  20120606 17:00:01

On 06/06/2012 12:54 PM, Ethan Gutmann wrote: > On Jun 6, 2012, at 10:49 AM, Michael Droettboom wrote: >> Interesting result. Note, however, that matplotlib will eventually turn >> all data arrays into float64 at rendering time, so any speed advantage >> to using integers will be lost by the subsequent conversion, I suspect. > I don't think it does if you pass uint8 to imshow, but otherwise you might be right. Sure. I was referring to scatter here. With imshow, of course, everything is ultimately turned into 8bitsperplane rgba. Mike 