Numpy

Sun 29 June 2025
import numpy as np
a = np.array([1, 2, 3])
print(a)
[1 2 3]
b = np.array([[1, 2], [3, 4]])
print(b)
[[1 2]
 [3 4]]
c = np.zeros((2, 3))
print(c)
[[0. 0. 0.]
 [0. 0. 0.]]
d = np.ones((3, 3))
print(d)
[[1. 1 …

Category: basics

Read More

Odd-Even

Sun 29 June 2025
def check_odd_or_even(input_number):

    if input_number % 2 == 0:
        return f"{input_number} is Even"

    return f"{input_number} is Odd"
check_odd_or_even(7)
'7 is Odd'
check_odd_or_even(8)
'8 is Even'
check_odd_or_even(0)
'0 is Even'
check_odd_or_even(-1)
'-1 is Odd'


Score: 5

Category: basics

Read More

Odd-Even2

Sun 29 June 2025
def odd_even():
    for i in range(10):      
        if i % 2 == 0:
              print(f"The number {i} is even")
        else:
            print(f"The number {i} is odd")
odd_even()
The number 0 is even
The number 1 is odd
The number 2 is even
The number 3 is odd
The number 4 …

Category: basics

Read More

Online-Image-Reader

Sun 29 June 2025
from PIL import Image
import numpy as np
import urllib.request
image_path = 'https://multimedia.bbycastatic.ca/multimedia/products/500x500/107/10736/10736343.jpg'
with urllib.request.urlopen(image_path) as url:
    with open('temp.jpg', 'wb') as f:
        f.write(url.read())

img = Image.open('temp.jpg')
img

png



Score: 5

Category: basics

Read More

Online-Image-Size

Sun 29 June 2025
from PIL import Image
import numpy as np
import urllib.request
image_path = 'https://multimedia.bbycastatic.ca/multimedia/products/500x500/107/10736/10736343.jpg'
with urllib.request.urlopen(image_path) as url:
    with open('temp.jpg', 'wb') as f:
        f.write(url.read())

img = Image.open('temp.jpg')
img

png

print(img)
<PIL …

Category: basics

Read More

Pandas

Sun 29 June 2025
import pandas as pd
s = pd.Series([10, 20, 30])
print(s)
0    10
1    20
2    30
dtype: int64
s = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
print(s)
a    10
b    20
c    30
dtype: int64
s = pd.Series({'a': 1, 'b': 2})
print(s …

Category: basics

Read More

Prettify-Error

Sun 29 June 2025
error_string = """
{
    "error": {
        "error_code": 1002,
        "error_message": "Unspecified Error",
        "details": "Unexpected error: ['Traceback (most recent call last):', '  File \"/home/rajaraman/rprojects/ml-api-work/ml-api-raja/services/mlapi/app/main.py\", line 228, in post_predict_classic_joblib_api', '    result_obj = await label_generator.match_with_multi(', '                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^', '  File \"/home/rajaraman/rprojects/ml-api-work/ml-api-raja/services/mlapi/app/label_generator.py\", line 770, in match_with_multi', '    feature_scores …

Category: basics

Read More

Python-Operators

Sun 29 June 2025
# Example 1 - Arithmetic Operators

print(1 + 2)
3
# Example 2 - Arithmetic Operators
print(2 + 3)
5
# Example 3 - Arithmetic Operators
print(3 + 4)
7
# Example 4 - Arithmetic Operators
print(4 + 5)
9
# Example 5 - Arithmetic Operators
print(5 + 6)
11
# Example 6 - Arithmetic Operators
print(6 + 2)
8
# Example 7 …

Category: basics

Read More

Random-Module

Sun 29 June 2025
import random
print(random.random())
0.487560015622336
print(random.randint(1, 10))
6
print(random.randrange(0, 20, 2))
12
print(random.choice(['red', 'green', 'blue']))
red
print(random.choices(['A', 'B', 'C'], k=5))
['C', 'B', 'C', 'B', 'A']
print(random.choices(['A', 'B', 'C'], k=5))
['A', 'C …

Category: basics

Read More

Randomized-Search

Sun 29 June 2025
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: C:\\Users\\Afia Jahan\\anaconda3\\envs\\py312; pyv: 3.12.11 | packaged by Anaconda, Inc. | (main, Jun  5 2025, 12:58:53) [MSC v.1929 64 bit (AMD64)]'
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split …

Category: basics

Read More
Page 5 of 7

« Prev Next »