8 ms·
From Python to Numpy
- guitarbill 10y ago> be warned that I'm a bit picky about typography & design: Edward Tufte is my hero And it shows, the theme is beautiful. Also some of the best ASCII diagrams I've seen. Worth a look at the source, even if you don't care about Python.
- keldaris 10y agoWouldn't normally criticize website design, but since this came up... yes, the fonts are pretty and all, but on my humble 24" monitor the site uses barely half of my horizontal space and looks awkward (the table of contents especially). "Mobile-first"?
- jiehong 10y ago> but on my humble 24" monitor the site uses barely half of my horizontal space and looks awkward (the table of contents especially). "Mobile-first"? That's actually a feature, as lines that are too long are harder to read (https://en.wikipedia.org/wiki/Line_length https://en.wikipedia.org/wiki/Line_length). It's the same as why books actually have empty margins. To me, the font is too thin to be easy to read.
- keldaris 10y agoI don't mind empty margins, but having 60% of my screen empty for no reason is excessive, and I do read slower because of it. If I want shorter lines, I'll just resize my browser, thanks. I agree with you about the font being too thin, but the line length annoyed me much more.
- richardwhiuk 10y agoMy problem is that the notes are off-screen - their seems to be an assumption that I'm reading on a widescreen monitor...
- Nicolas-Rougier 10y agoYes, sorry for that. I need to work a bit more on a more responsive CSS.
- JeremyBanks 10y agoOptimizing for super-rare users who have a deliberate desire for long lines is less important than optimizing for the vastly-more-common case that the browser's size is large as an artifact of content the user was viewing on a previous site, but the user still prefer a sane line length for text content.
- tomrod 10y agoCitation that these users are super rare? Almost everyone I've had conversations with on the subject bemoan too large margins on websites.
- omaranto 10y agoThat's odd. I wonder if these people that like looong lines are mostly younger people that have read more from screens than books (but not so young that they've read more from phones than computer screens :))? A book with very long lines would be super weird.
- tomrod 10y agoAgreed. I'm specifically referencing wasted space. As I've gotten older, that "wasted" space gets replaced with zoomed fonts using ctrl+=. I've found this attitude and use isn't all that unique anecdotally, so I found the assertion that it's "rare" to be contrary to my own experience. I have no citation the other way though!
- deleted 10y ago[deleted]
- Sean1708 10y agoOn the flip side you can use Reader Mode to make long lines shorter, but you can't use Anti-Reader Mode to make short lines longer.
- deleted 10y ago[deleted]
- wott 10y agoFonts are barely readable: too thin, too white on my browser/screen.
- Nicolas-Rougier 10y agoThanks. If you love ascii art, make sure to have a look at https://casual-effects.com/markdeep/ https://casual-effects.com/markdeep/
- jajool 10y agothis book is amazing! specially the authors sense of humor makes reading it fun. > For example, can you tell what the two functions below are doing? Probably you can tell for the first one, but unlikely for the second (or your name is Jaime Fernández del Río and you don't need to read this book).
- danso 10y agoImmediately recognized the domain name. Months ago I was doing yet another search on how to do geospatial plotting with Matplotlib, the kind that mostly works-out-of-the-box in R/ggplot2, but, because of some latent fragmentation from Py2v3, was not well-documented anywhere in Python/matplotlib. And while I've come to really like and respect Matplotlib, the documented examples stray far from what they should for purposes of API illustration, and so learning it has been a test in patience. Anyway, Mr. Rougier's Matplotlib was both informative, concise, and beautiful. Actually, I think my appreciation for matplotlib came from reading his guide: https://www.labri.fr/perso/nrougier/teaching/matplotlib/ https://www.labri.fr/perso/nrougier/teaching/matplotlib/
- grej 10y agoAs someone who has used numpy for many years and written a great deal of production code using it, I was surprised when I read through this and saw some numpy tricks that I didn't know regarding the speeds of various operations! This is really a fantastic reference that provides a deeper level of understanding of what numpy does under the hood. One thing I will highlight that the author just touched on briefly, is that numpy combined with numba is really a phenomenal combination for dealing with very computationally intensive problems. The folks at Continuum Analytics have really done a fantastic job building numba (numba.pydata.org), which JIT compiles a subset of python functions using LLVM, and is designed to work seamlessly with numpy arrays. Numba makes it much easier to speed up performance bottlenecks and allows you to easily create numpy ufuncs which can take advantage of array broadcasting.
- marmaduke 10y agoJust to jump on the numba train, I've generally found it to reliably obtain C like performance from C-like Python code. This property also holds when you use Python as a preprocessor language for generating computational kernels, which provides a lot of flexibility not evident in the documentation. It also has simple-to-use openmp-like multicore parallelization, limited class support, AOT compilation and CUDA & AMD HSAIL support.
- infinite8s 10y agoAre you using python as a preprocessor to glue together text strings of numba code which you then eval? Or are you using python to generate the numba AST?
- vegabook 10y agoTravis Oliphant, Numpy creator, is CEO of Continuum Analytics.
- darkseas 10y agoCan I ask how intensively you have used Numba and over what period? I'm interested in how Numba has progressed over the last few years, with a view to using it over Cython. My team and I looked at Numba a year ago or so for optimisation of a fairly large calculation, and found that the speed-ups were impressive where they worked, but were not consistent or predictable. We used Cython for large parts, and while there was boilerplate and incantations, the gains were achievable, incremental and certain. The annotation tools were also quite helpful for identifying bottlenecks where Cython code could be effective. Incidentally, once we decided that Cython was our go-to tools, we often wrote simple looping code rather than vectorised code because it was simpler to transition to Cython, alá Julia.
- BanzaiTokyo 10y agoDoes the book exist in PDF?
- Nicolas-Rougier 10y agoNot yet but I'm working on it (meanwhile you can try a rst2latex.py on the sources) for a very rough draft.
- dbyte 10y agoAmazing work. If you take a look at latex please consider also XeTeX for its beautiful font support. It can give a lot of satisfaction when packaging good content. Microtype is also nice if one sticks to pdflatex.
- d0mine 10y agoI've failed to build pdf from book.tex produced by rst2latex.py (the issues are likely fixable if you work with latex). I've converted the rst files to e-book using rst2html.py + calibre instead.
- masnick 10y agoThe site is down for me, but you can see the content nicely formatted on GitHub: https://github.com/rougier/from-python-to-numpy https://github.com/rougier/from-python-to-numpy For cmd-f: mirror
- gonvaled 10y agoYou mean search? Not everybody uses a Mac ...
- lgas 10y agoYet somehow you figured out what he meant.
- gonvaled 10y agoIt was not tongue in cheek. I do not know what cmd is. I assume it is a modifier key in an Apple keyboard, since it is not in a Windows keyboard, which I have (although I am on linux). Sure, I guess he means search, but he could just say that. Or should I start talking using references to my keyboard shortcuts? I mostly use emacs, very often with custom bindings, or tmux, so it will not make sense to a lot of people. But hey, it's a free world.
- deleted 10y ago[deleted]
- syntaxing 10y agoDoes anyone have a recommendation for something similar to this but for Python itself? I have been trying to find something that is not necessarily an intro or crash course book but a book with tips, great explanations, and neat examples (which this e-book(?)/site has). I see that the author has responded to a couple comments here. Thank you for your great work! It's always great to have a nice reference material with concise examples. I think this will be helpful to everyone(beginners and advanced python users alike)!
- haldora 10y agoI would recommend Julien Danjou's "The Hacker's Guide to Python". He charges $29 for the PDF, but provides updates every year or so. I think it's a great book for getting more depth out of Python. :) Topics include: modules/libraries, documentation, distribution, virtual environments, unit testing, methods/decorators, functional programming, optimization, scaling, RDBMS, and more. https://thehackerguidetopython.com/ https://thehackerguidetopython.com/
- syntaxing 10y agoThanks for the suggestion! I downloaded the free chapter from the book and I'm going to check it out tonight. If I enjoy it, I might have to buy the physical and electronic copy!
- Nicolas-Rougier 10y agoThank you. For some Python introduction, you can have a look at the end of this page: https://github.com/rougier/Scipy-Bordeaux-2016/blob/master/introduction.md https://github.com/rougier/Scipy-Bordeaux-2016/blob/master/i...
- syntaxing 10y agoThank you for the suggestion!
- bcbrown 10y agoI'm skimming through Effective Python, and so far I think it's a pretty good "best practices" guide for intermediate Python developers.
- hayd 10y agoIs there an epub/mobi version?
- mmmBacon 10y agoI'd be very curious to know if there is any impact to choosing Numpy C ordered arrays or Fortran ordered arrays. As a long time Matlab user (since 1993) who moved to Python 3 years ago, I have always defaulted to Fortran order because it was what I was used to and seemed more intuitive. I did play with C ordered arrays but didn't find an advantage in my limited investigation.
- zwieback 10y agoI think it depends on whether an algorithm is forced to traverse an array in the cache-efficient direction or not. Oftentimes you can't choose whether to make your outer loop rows or columns so the performance could go either way.
- travisoliphant 10y agoThere may still be a few routines that expect C-ordered arrays and so require a copy be made when given a Fortran-ordered array --- especially as you extend to one of libraries that use NumPy. For the most, part, however, Fortran-ordered arrays should work well. It all comes down to the expectation of the routine writer.
- zellyn 10y agoAnyone (author) know what was used to generate the cover image of cubes and shadows? Edit: it's sketchup - there's a .skp file in the data/ subdirectory of the github repo for the book.
- deleted 10y ago[deleted]
- gerfficiency 10y agoI really appreciated the problem vectorization chapter. New approaches require new thinking and this is often forgotten when teaching new concepts.
- tu7001 10y agoI just check the first example from introduction to vectorization: http://www.labri.fr/perso/nrougier/from-python-to-numpy/#id5 http://www.labri.fr/perso/nrougier/from-python-to-numpy/#id5, (add_python and add_numpy) and benchmark results are nearly the same: 75.4ns and 77.7ns accordingly.