💾 Archived View for gem.sdf.org › s.kaplan › cheatsheets › libraries-and-frameworks › numpy.md captured on 2024-08-31 at 12:50:39.
⬅️ Previous capture (2023-09-08)
-=-=-=-=-=-=-
# NumPy Cheatsheet NumPy is a popular Python library for numerical computing. It provides a wide range of tools for working with arrays, matrices, and numerical operations. This cheatsheet provides a quick reference for some of NumPy's unique features, including code blocks for creating arrays, indexing, slicing, broadcasting, and more. Additionally, it includes a list of resources for further learning. ## Creating Arrays
import numpy as np
x = np.array([1, 2, 3])
y = np.array([[1, 2], [3, 4]])
np.zeros((3, 3))
np.ones((2, 2))
np.arange(0, 10, 2)
np.random.rand(3, 3)
np.random.randn(3, 3)
## Indexing and Slicing
x[0]
y[0, 1]
x[1:3]
y[:, 1]
x[x > 2]
## Broadcasting
x + 1
x + y
x * y
x * 2
## Other Useful Features
np.dot(x, y)
y.T
x.reshape((3, 1))
x.sum()
x.mean()
x.std()
## Resources - [NumPy documentation](https://numpy.org/doc/stable/) - [NumPy quickstart tutorial](https://numpy.org/doc/stable/user/quickstart.html) - [Python Data Science Handbook](https://jakevdp.github.io/PythonDataScienceHandbook/index.html)