-
-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anatomy of an array introduction. Obvious way is the fastest. #29
Comments
Thanks for the report. Your results are surprising. Could you also test using IPython and the magic Note: I edited your post because the listing was not displayed properly. |
Thanks for the answering. I will try a little bit later and post here the results |
Hi! To start, thank you for great tutorial! timeit("Z[...] = 0", globals())
timeit("Z.view(np.float64)[...] = 0", globals())
timeit("Z.view(np.float32)[...] = 0", globals())
timeit("Z.view(np.float16)[...] = 0", globals())
timeit("Z.view(np.complex)[...] = 0", globals())
timeit("Z.view(np.int64)[...] = 0", globals())
timeit("Z.view(np.int32)[...] = 0", globals())
timeit("Z.view(np.int16)[...] = 0", globals())
timeit("Z.view(np.int8)[...] = 0", globals())
timeit("Z.fill(0)", globals()) I've measured on two computers, with: Python 3.6.4 The specs of the first computer:
The specs of the second computer:
As you can see, the results are somewhat consistent with each other, but do not match your observations. |
Given the consistent output from you and @ruichernob it looks that I might be wrong. I don't remember how did I come to this conclusion. I'm pretty sure I got the results written in the book but I might be the only one in the end 😄. Would you mind proposing a PR to fix what's written in the book? |
It would be great if you had the opportunity to recheck these results on your computer with current version of Since the basic idea of this section is that the obvious method is not optimal, just a change in the timings will make this section meaningless. As for me, the only obvious way to fill the entire array with some value is to use the I've tried to come up with a same simple example where such tricks will allow to overtake another obvious way, but unfortunately not yet found :) In addition, "There should be one-- and preferably only one --obvious way to do it." Having said this, if the fresh results you rechecked will be in agreement, I would just skip this example so as not to be misleading. I apologize that I can not offer an example for replacement. |
On OSX 10.13.3, Pyton 3.6.4, numpy 1.14.2, I got:
|
Thank you, interesting results! Could you still |
More or less the same:
|
Hello,
I've tried this code:
And gave following results:
100 loops, best of 3: 905 usec per loop
100 loops, best of 3: 918 usec per loop
100 loops, best of 3: 925 usec per loop
100 loops, best of 3: 915 usec per loop
100 loops, best of 3: 910 usec per loop
100 loops, best of 3: 912 usec per loop
100 loops, best of 3: 902 usec per loop
100 loops, best of 3: 1.9 msec per loop
100 loops, best of 3: 1.91 msec per loop
And i don't understand the root cause of such opposite results. Could you kindly clarify?
Thanks in advance.
P.S. I'm using python 3.5.2 64bit version along with Anaconda.
The sysinfo() output:
Date: 01/02/17
Python: 3.5.2
Numpy: 1.11.1
Scipy: 0.17.1
Matplotlib: 1.5.1
The text was updated successfully, but these errors were encountered: