4
$\begingroup$

Lately, I've been finding that I often need to compute various things and graph some pretty complicated functions. I've realized that learning to program, especially in Python, could be really helpful for this.

However, I'm not a big fan of learning from videos, I much prefer reading books. So, I'm looking for book recommendations that can help me learn Python specifically for its use in mathematics.

Thanks in advance!

$\endgroup$
10
  • $\begingroup$ I agree that you will do better by going with a book. Having never used Python myself, I am unsure which programming language that you should adopt (e.g. C, Java, Python, ...). Personally, I strongly suspect that you will do better with Python, as your 1st programming language, than Java or C. My understanding is that Python is a good language to use for math problems. Beyond that, choice of book should be customized to your abilities and work habits. I suggest looking for pdf copies of Python books on the internet, finding one that suits you, and then buying the corresponding book. $\endgroup$ Commented Jun 13, 2024 at 18:10
  • $\begingroup$ For what it's worth, I am a retired programmer, which (moderately) explains my previous comment. In fact, your posted question, and any similar questions, are off topic for the MathSE forum, which is devoted to math problems, rather than computer software issues/problems. $\endgroup$ Commented Jun 13, 2024 at 18:12
  • $\begingroup$ @user2661923: " In fact, your posted question, and any similar questions, are off topic for the MathSE" then what community should I ask this question in? stack overflow doesn't have the tag book-recommendation so probably any book question is off topic . $\endgroup$ Commented Jun 14, 2024 at 6:36
  • $\begingroup$ First of all: congratulations that you chose python. It is free, easy to install and has a lot of built in features. If you prefer books and have never used python grab just any book that introduces you into the python basics. After you got over those hurdles you will have little trouble to learn from the internet how to use the math packages that python offers. There are too many of them and they are under constant development. Learning them from books isn't the best approach. $\endgroup$ Commented Jun 14, 2024 at 6:59
  • 1
    $\begingroup$ Agree with @KurtG. , there aren't any general books like this that can help you, but the flow should be: learn the basics $\rightarrow$ practice $\rightarrow$ search the net for any package/mathy thing you need, when you need them. For practice, peoject euler seems to be best for you, as it is mainly math problems hackerrank.com/contests/projecteuler/challenges $\endgroup$ Commented Jun 14, 2024 at 10:29

5 Answers 5

5
$\begingroup$

Although I myself have not read this book, but I think "Doing Math With Python" (published by No Starch Press) can be a good start.

I believe it focuses on learning Python through the lens of using it for mathematics purposes. Here are its contents:

  • Acknowledgements
  • Introduction
  • Working with Numbers
  • Visualizing Data with Graphs
  • Describing Data with Statistics
  • Algebra and Symbolic Math with SymPy
  • Playing with Sets and Probability
  • Drawing Geometric Shapes and Fractals
  • Solving Calculus Problems
  • Afterword
  • Appendix A: Software installation
  • Appendix B: Overview of Python Topics
  • Index

You can find a PDF version of this book online for free. Here is its cover page: book cover

$\endgroup$
4
$\begingroup$

Everyone learns differently, and for something like Python that's meant to be so organic and intuitive and more of a friendly wrapper or interface for huge chunks of compiled code that is community supported and tested, you may find that once you get the hang of Python's basic premise - everything is an object, and it's the object's attributes called methods that do stuff - then you may find you can put the book down, and just start trying things.

When you get stuck, try Python's incredibly useful help(object.attribute) for usually quite helpful documentation, or go to the online documentation for the package you are using which should be about the same.

I probably type

import numpy as np
import matplotlib.pyplot as plt
import scipy.special as spe
from scipy.optimize import minimize

several times a day.

Want to diagonalize a matrix? Type help(np.linalg.eig).

Want to minimize? Type help(minimize).

Need a specific kind of Bessel function or elliptic integral, type help(scipy.special)

The first hurdle is that everything is an object. There is a moment where it makes no sense, then suddenly it becomes easy and intuitive.

The second hurdle is numpy arrays. Numpy also has matrix objects, but a lot of the time we actually need n-dimensional arrays. Numpy's arrays can do amazing things with indexing and broadcasting, so go straight to those chapters first.

The third hurdle is to learn to read and trust the verbose and (usually) very helpful error messages. We all make syntax errors regularly, or mix dimensions of arrays. When you see an error message, treat it as a trusted friend. Embrace it, and read through carefully. If you don't understand the error message, paste the key part into a Google search and you will immediately see how other people solved the same problem!

Despite the title, you may find that Jake VanderPlas' Python Data Science Handbook has some explanations (especially for Numpy) that are very accessible and get you started quickly.

I think that once you start playing with Python and especially reading documentation and error messages, you'll put the book down and just dig in in your own, unique learning-style way.

Here's an example of something I got from one of Jake's blogpost in my answer to How do I create a 3D line plot in matplotlib from the data in arrays?

Here is the Lorenz attractor both in 3D and animated...

Here is the Lorenz attractor both in 3D and animated

Here is a minimal, simplified example of plotting lines in 3D based on the above:

def lorentz_deriv((x, y, z), t0, sigma=10., beta=8./3, rho=28.0):
    """Compute the time-derivative of a Lorentz system."""
    return [sigma * (y - x), x * (rho - z) - y, x * y - beta * z]

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.integrate import odeint as ODEint

x = np.linspace(0, 20, 1000)
y, z = 10.*np.cos(x), 10.*np.sin(x) # something simple

fig = plt.figure()
ax = fig.add_subplot(1,2,1,projection='3d')
ax.plot(x, y, z)

# now Lorentz
times = np.linspace(0, 4, 1000) 

start_pts = 30. - 15.*np.random.random((20,3))  # 20 random xyz starting values

trajectories = []
for start_pt in start_pts:
    trajectory = ODEint(lorentz_deriv, start_pt, times)
    trajectories.append(trajectory)

ax = fig.add_subplot(1,2,2,projection='3d')
for trajectory in trajectories:
    x, y, z = trajectory.T  # transpose and unpack 
    # x, y, z = zip(*trajectory)  # this also works!
    ax.plot(x, y, z)

plt.show()
$\endgroup$
1
$\begingroup$

Exploring University Mathematics with Python by Siri Chongchitnan https://link.springer.com/book/10.1007/978-3-031-46270-2

$\endgroup$
-2
$\begingroup$

I know of an online book which deals with statistics and use r studio to plot, not Python. I think it is great. You can have a try! http://rafalab.dfci.harvard.edu/dsbook/summary-statistics.html

$\endgroup$
1
  • $\begingroup$ Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. $\endgroup$ Commented Jul 8, 2024 at 4:49
-2
$\begingroup$

Well, there are lots of good books that may help you in learning Python in the service of mathematics. Here below there are some books that I would like to recommend to you.

  1. Doing Math with Python by Amit Saha
  2. Applying Math with Python by Sam Morley
  3. Python for Mathematicians by Ms Menaka B
  4. Python Programming for Mathematics by Stephen Lynch
  5. Mathematical Logic Through Python by José María Almira
  6. Explore Python for Mathematics by Vijay Shinde
  7. Python for Mathematics by Vincent Knight
  8. Mathematical Python by Patrick J. Walls and Jay Gopalakrishnan

I hope it will help you.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.