#NumPy cheat sheet for #datascience :
*Array Creation*
1.
2.
3.
4.
5.
6.
*Array Operations*
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
*Array Indexing*
ادامه در پست بعد👇
#cheat_sheet #Python
🆔 @Python4all_pro
*Array Creation*
1.
numpy.array() - Create an array from a list or other iterable.2.
numpy.zeros() - Create an array filled with zeros.3.
numpy.ones() - Create an array filled with ones.4.
numpy.empty() - Create an empty array.5.
numpy.arange() - Create an array with evenly spaced values.6.
numpy.linspace() - Create an array with evenly spaced values.*Array Operations*
1.
+ - Element-wise addition.2.
- - Element-wise subtraction.3.
* - Element-wise multiplication.4.
/ - Element-wise division.5.
** - Element-wise exponentiation.6.
numpy.sum() - Sum of all elements.7.
numpy.mean() - Mean of all elements.8.
numpy.median() - Median of all elements.9.
numpy.std() - Standard deviation.10.
numpy.var() - Variance.*Array Indexing*
ادامه در پست بعد👇
#cheat_sheet #Python
🆔 @Python4all_pro
#NumPy cheat sheet for #datascience :
*Array Creation*
1.
2.
3.
4.
5.
6.
*Array Operations*
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
*Array Indexing*
1.
2.
3.
*Array Reshaping*
1.
2.
3.
*Array Manipulation*
1.
2.
3.
4.
*Mathematical Functions*
1.
2.
3.
4.
5.
*Statistical Functions*
1.
2.
3.
4.
*Random Number Generation*
1.
2.
3.
*Linear Algebra*
1.
2.
3.
#cheat_sheet #Python
🆔 @Python4all_pro
*Array Creation*
1.
numpy.array() - Create an array from a list or other iterable.2.
numpy.zeros() - Create an array filled with zeros.3.
numpy.ones() - Create an array filled with ones.4.
numpy.empty() - Create an empty array.5.
numpy.arange() - Create an array with evenly spaced values.6.
numpy.linspace() - Create an array with evenly spaced values.*Array Operations*
1.
+ - Element-wise addition.2.
- - Element-wise subtraction.3.
* - Element-wise multiplication.4.
/ - Element-wise division.5.
** - Element-wise exponentiation.6.
numpy.sum() - Sum of all elements.7.
numpy.mean() - Mean of all elements.8.
numpy.median() - Median of all elements.9.
numpy.std() - Standard deviation.10.
numpy.var() - Variance.*Array Indexing*
1.
arr[i] - Access ith element.2.
arr[i:j] - Access slice from ith to jth element.3.
arr[i:j:k] - Access slice with step k.*Array Reshaping*
1.
arr.reshape() - Reshape array.2.
arr.flatten() - Flatten array.3.
arr.ravel() - Flatten array.*Array Manipulation*
1.
numpy.concatenate() - Concatenate arrays.2.
numpy.split() - Split array.3.
numpy.transpose() - Transpose array.4.
numpy.flip() - Flip array.*Mathematical Functions*
1.
numpy.sin() - Sine.2.
numpy.cos() - Cosine.3.
numpy.tan() - Tangent.4.
numpy.exp() - Exponential.5.
numpy.log() - Natural logarithm.*Statistical Functions*
1.
numpy.min() - Minimum value.2.
numpy.max() - Maximum value.3.
numpy.percentile() - Percentile.4.
numpy.quantile() - Quantile.*Random Number Generation*
1.
numpy.random.rand() - Random numbers.2.
numpy.random.normal() - Normal distribution.3.
numpy.random.uniform() - Uniform distribution.*Linear Algebra*
1.
numpy.dot() - Dot product.2.
numpy.matmul() - Matrix multiplication.3.
numpy.linalg.inv() - Matrix inverse.#cheat_sheet #Python
🆔 @Python4all_pro
👍5
👍4🔥1
Please open Telegram to view this post
VIEW IN TELEGRAM
image_2025-08-17_09-32-25.png
983.2 KB
1. Swap variables without a temporary one
a, b = 5, 10
a, b = b, a
2. One-line if-else (ternary)
result = "Even" if x % 2 == 0 else "Odd"
3. List Comprehension
squares = [x**2 for x in range(10)]
evens = [x for x in range(10) if x % 2 == 0]
4. Set and Dict Comprehension
unique = {x for x in [1,2,2,3]} # remove duplicates
squares = {x: x**2 for x in range(5)} # dict comprehension5. Most common element in a list
from collections import Counter
most_common = Counter(['a','b','a','c']).most_common(1)[0][0]
6. Merging dictionaries (Python 3.9+)
a = {'x': 1}
b = {'y': 2}
merged = a | b7. Returning multiple values
def stats(x):
return max(x), min(x), sum(x)
high, low, total = stats([1, 2, 3])
8. Using zip to iterate over two lists
names = ['a', 'b']
scores = [90, 85]
for n, s in zip(names, scores):
print(f"{n}: {s}")
9. Flattening nested lists
nested = [[1,2], [3,4]]
flat = [item for sublist in nested for item in sublist]
10. Default values in a dictionary
from collections import defaultdict
d = defaultdict(int)
d['apple'] += 1 # no KeyError
11. Lambda in one line
square = lambda x: x**2
print(square(4))
12. enumerate with index
for i, v in enumerate(['a', 'b', 'c']):
print(i, v)
13. Sorting by key or value
d = {'a': 3, 'b': 1, 'c': 2}
sorted_by_val = sorted(d.items(), key=lambda x: x[1])14. Reading file lines into a list
with open('file.txt') as f:
lines = f.read().splitlines()15. Type Hints
def add(x: int, y: int) -> int:
return x + y
#پایتون #Python
Please open Telegram to view this post
VIEW IN TELEGRAM
❤2
Advanced Python Cheatsheet Curated.pdf
850.5 KB
Advanced python cheat sheet
👈 با هشتگ #cheat_sheet میتونید بقیه چیتشیتها رو در کانال پیدا کنید
#پایتون #Python #هوش_مصنوعی
📱 @Python4all_pro
#پایتون #Python #هوش_مصنوعی
Please open Telegram to view this post
VIEW IN TELEGRAM