This month I am aiming to re-introduce myself to Python coding. This week, I decided to follow along to Jay Alammar’s post that I found on Hacker News.
His write-up focuses on NumPy, a foundational library that unlocks data analysis and machine learning in Python. Let’s import it and get started.
A fundamental building block of NumPy is the ability to create “arrays”, which can be anywhere from 1 to 3+ dimensions.
There are various options for how to create an array:
- Specific the values in the array: np.array([1,2,3])
- Create an array of all 1’s or all 0’s: np.ones(3) or np.zeros(5) based on how many values desired
- Create an array of random decimals: np.random.random(8)
Once we have two arrays with the same dimension, we can add or multiply them. For individual arrays, we can scale them, find the max value, or sum them.
But arrays can contain multiple dimensions. This is when it starts to get interesting. We can do mathematical functions across the dimensions.
Even if they are different shapes, we can still do the math functions.
We can reshape an array by specifying the dimensions we want, or even transpose.
Building on all this, we can add a third dimension.
We can apply a 3-dimensional array to 2-dimension values over time, red/green/blue values for each pixel of an image, or feeding text data to a machine learning model.
With NumPy, the possibilities are endless. That’s all for this week.