
Introduction to Python for Computational Science and Engineering [pdf] - danso
http://www.southampton.ac.uk/~fangohr/training/python/pdfs/Python-for-Computational-Science-and-Engineering.pdf
======
drej
> As Python 2.x is still the default Python on many system and there are a
> fair number of research codes out there based on Python 2, we will use
> Python 2.x in this book.

This is so unfortunate. Scientific computing is riddled with technical debt
and _starting_ with Python 2 today is fairly irresponsible. If you're already
invested in Python 2 and have code/training written up, fine. But if you're
learning it just now, as the book's audience obviously is, picking Python 3
should be a no brainer.

~~~
rishabguha
IMO, Python 3's support for matrix multiplication using the @ operator is
itself worth the cost of admission. Much of technical computing is just
implementing algorithms that use linear algebra extensively, and if you're
coming from matlab littering your code with dot(dot(X,Y),Z) is a real pain

~~~
godelski
I actually see np.dot(np.dot(x,y),z) as easier to read and remember. It is
more explicit in what it is doing. Being explicit is a good thing.

~~~
noobermin

       a + 4*(x-y) + b**5
    

vs

    
    
       (+ a (* 4 (- x y )) (expt b 5 ))
    

Sometimes, as arithmetic with lisp shows, conciseness is better. Also, it
isn't being more _explicit_ than it is being more _verbose_.

~~~
kazinator
It is abosolutely being more explicit. It's being more explicit that (expt b
5) is a unit that forms a single argument in the + form.

This is implicit in

    
    
      a + b ** 5
    

according to a precedence rule between the __and + operator, which is hidden
in the parser 's implementation and in documentation thereof.

Well, the white-spacing

    
    
      a + b**5
    

_suggests_ it. But the suggestions produced by insignificant whitespace can be
mere wishful thinking:

    
    
      int* x, y; // two C pointers? not!
    

Speaking of whitespace, also have the advantage of there being multiple ways
to split the expression into multiple lines, all conforming to a very clear,
simple formatting rule:

    
    
      (+ a
         (* 4 (- x y))
         (expt b 5))
    
      (+ a
         (* 4
            (- x y))
         (expt b 5))
    

Fully expanded, every term on separate line:

    
    
      (+ a
         (* 4
            (- x
               y))
         (expt b
               5))
    

In this manner, we can write complex expressions that would be quite
unreadable in infix, requiring break-up into intermediate temporaries.

We almost have a circuit diagram now with "gates" for the operations: a three
input + gate, etc:

    
    
         ____
        /    |- a
        |    |      ____
      --| +  |-----/    |- 4
        |    |     |  * |      ____
        \____|-    |    |-----/    |- x
               `   \____|     | -  |
                |             \____|- y
                |   _____     
                `--/     |- b
                   | expt|
                   \_____|- 5

------
fangohr
Hi all, I am the author of the book.

There is a Python 3 version of the book available at
[http://www.southampton.ac.uk/~fangohr/teaching/python/book.h...](http://www.southampton.ac.uk/~fangohr/teaching/python/book.html)

This also includes Jupyter Notebook files for those who want to execute (and
play around with) the chapter content interactively.

Thank you for all the comments and discussion.

Hans (fangohr@soton.ac.uk)

~~~
stared
It looks wonderful! Just yesterday I did a quick workshop introducing
neuroscience to scientific Python, in the Jupyter Notebook environment (very
rough version here: [https://github.com/stared/python-
neuroaspects-2016](https://github.com/stared/python-neuroaspects-2016), before
updates). I will definitely sent the participants a link to your book.

But one small question: do you plan, by any chance, upload your notebooks to
GitHub (or any other place, where one can easily see a rendered version; BTW
one more selling point of Jupyter - the easiness to share)?

~~~
fangohr
Thank you. It is on my todo list.

------
a3n
I'm very sympathetic to "use python2." I still use python2.

But we should all keep in mind the "no shit really this time" EOL for python
is 2020.
[http://legacy.python.org/dev/peps/pep-0373/](http://legacy.python.org/dev/peps/pep-0373/)

Even if you say "well, it'll just be forked," you don't really know how many
forks and pain there will be. Maybe python2 will be like LibreOffice, or maybe
it will be like OpenOffice.

Like it or not, python3 is the future.

~~~
module0000
And the bucket of people who _want_ python2 forked weighed against the bucket
of people can _can_ fork/maintain it are not equal.

------
mynegation
This is a very good guide. I thought I knew python ecosystem well and I found
something new for myself ('visual' package for 3D illustrations).

I am wondering if there are guides for the "reverse direction": I already know
how to program, but I want to learn new scientific domain that is interesting
to me: e.g. material science, climate modeling, etc. Something like
Rosalind[1] does for bioinformatics.

[1] [http://rosalind.info/](http://rosalind.info/)

~~~
godelski
Well if you want to learn the science, you can just pick up a science book. I
know many users here have good suggestions. But if you are specifically
looking for scientific computing those generally talk about code basics. There
are also numeric programming books. If you're trying to get into those studies
I suggest going through a numerics book because the techniques will be similar
among any of the code. But you'll have to spend time learning the non-coding
parts as well. In science coding is just a tool.

------
fangohr
Just found a page dedicated to Python 3 for scientists: [https://python-3-for-
scientists.readthedocs.io/en/latest/](https://python-3-for-
scientists.readthedocs.io/en/latest/)

Also an impressive line up of scientific tools that will drop Python 2 support
by 2020: [http://www.python3statement.org](http://www.python3statement.org)

(And for completeness: the book discussed in this thread is available for
Python 3 at
[http://www.southampton.ac.uk/~fangohr/teaching/python/book.h...](http://www.southampton.ac.uk/~fangohr/teaching/python/book.html)
)

------
embleton
I just finished working through this book and I really enjoyed it. I went from
next to no Python knowledge to writing programs to analyze raw vibration data
in a few days. I had previous experience with Matlab and this book was very
useful in bridging the gap between the two systems.

------
Normal_gaussian
I'm dubious about the worth of this book as I lived with several soton
Engineering students as they went through the associated course (whilst I did
CS as part of the other 'Engineering' faculty, ECS), though a lot may have
been due to lack of engagement with this particular course (copying and
memorisation were sufficient to get you through it). I was always so
frustrated that my friends couldn't benefit from some of the great lecturers
in my own faculty.

That said I know a few Engineering students there now who are awesome
programmers (though Aero Engineers at heart, so I can't hire them :( ).

------
dschiptsov
Python3 as default dialect!

~~~
dschiptsov
What exactly is wrong with this particular comment?)

~~~
anc84
It does not contribute anything meaningful to the discussion on the submitted
link.

~~~
dschiptsov
It does. It emphasizes that this particular guide encourages use of Python3,
instead of holding onto legacy, which means that the author understands
programming languages basics or at lest knows which semantic unification has
been done to make the language less inconsistent, hence more beautiful.

