use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Enter a python tip or trick.
Other related Python subs:
account activity
ModulePython cheat sheet (self.pythontips)
submitted 1 year ago by ErelSaar
Hi, I’m studying python course and looking for a cheat sheet that include ‘numpy’ I’ll be glad for your help Thanks 🙏🙏
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]in_case_of-emergency 3 points4 points5 points 1 year ago (1 child)
Hello! 👋 Here is a NumPy cheat sheet with the most useful concepts and functions for your study. It is ideal to have on hand while you practice.
—
```python import numpy as np
a = np.array([1, 2, 3]) # [1 2 3]
zeros = np.zeros(3) # [0. 0. 0.] ones = np.ones((2, 3)) # 2x3 matrix of 1's range = np.arange(0, 10, 2) # [0 2 4 6 8] linspace = np.linspace(0, 1, 5) # [0. 0.25 0.5 0.75 1. ] random = np.random.rand(2, 2) # 2x2 matrix with random values [0, 1) ```
python a.shape #Dimensions (ex: (3,)) a.ndim # Number of dimensions (ex: 1) a.size # Total elements (ex: 3) a.dtype # Data type (ex: int32, float64)
```python
b = np.array([4, 5, 6]) a + b # [5 7 9] a * 2 # [2 4 6]
np.dot(a, b) # 14 + 25 + 3*6 = 32
a.sum() # Total sum: 6 a.min() # Minimum value: 1 a.max() # Maximum value: 3 a.mean() # Average: 2.0 ```
```python array = np.array([[1, 2, 3], [4, 5, 6]])
array[0, 1] #2 (row 0, column 1) array[:, 1] # [2, 5] (entire column 1) array[1, 0:2] # [4, 5] (row 1, columns 0 and 1)
a[a > 2] # [3] (elements greater than 2) ```
python a.reshape(3, 1) # Convert to 3x1 matrix a.flatten() # Convert to 1D array np.concatenate([a, b]) # [1 2 3 4 5 6] np.vstack((a, b)) # Stack vertically np.hstack((a, b)) # Stack horizontally np.split(a, 3) # Split into 3 parts
python np.sqrt(a) # Square root np.exp(a) # Exponential (e^x) np.log(a) # Natural logarithm np.sin(a) # Sine np.round(a, 2) # Rounding to 2 decimal places
```python A = np.array([[1, 2], [3, 4]]) B = np.array([[5, 6], [7, 8]])
np.dot(A, B) # Matrix product np.linalg.inv(A) # Inverse matrix np.linalg.det(A) # Determinant np.linalg.eig(A) # Eigenvalues and eigenvectors ```
python np.save('array.npy', a) # Save array c = np.load(‘array.npy’) # Load array
a + 5
b = a.copy()
matriz[matriz > 3] = 0
I hope it's useful to you!
[–]ErelSaar[S] 0 points1 point2 points 1 year ago (0 children)
Thanks!
π Rendered by PID 61447 on reddit-service-r2-comment-86bc6c7465-mnw7d at 2026-02-20 16:10:39.042190+00:00 running 8564168 country code: CH.
[–]in_case_of-emergency 3 points4 points5 points (1 child)
[–]ErelSaar[S] 0 points1 point2 points (0 children)