Numpy Tensorflow

Mon 30 June 2025
import numpy as np

arr_1 = np.arange(1).reshape(-1, 1)
squared_1 = arr_1 ** 2
summed_1 = np.sum(squared_1)
meaned_1 = np.mean(squared_1)
maxed_1 = np.max(squared_1)

print("Cell 1 - Numpy")
print("Array shape:", arr_1.shape)
print("Sum:", summed_1)
print("Mean:", meaned_1)
print("Max:", maxed_1)
Cell 1 - Numpy
Array shape: (1 …

Category: basics

Read More

Oop

Mon 30 June 2025
class Person:
    pass
p1 = Person()
print(type(p1))
<class '__main__.Person'>
class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age
s1 = Student("Sara", 20)
print(s1.name, s1.age)
Sara 20
class Dog:
    def __init__(self, breed):
        self.breed = breed

    def bark(self):
        print("Woof! I …

Category: basics

Read More

Pytest Pytorch Scipy Tensorflow

Mon 30 June 2025
# Cell 1 - Pytest Example
def add_1(a, b):
    return a + b + 1

def test_add_1():
    assert add_1(1, 2) == 4

test_add_1()
print("Pytest Cell 1 Passed")
Pytest Cell 1 Passed
# Cell 2 - Pytest Example
def add_2(a, b):
    return a + b + 2

def test_add_2():
    assert add_2(2, 3) == 7

test_add_2()
print …

Category: basics

Read More

Python Advanced

Mon 30 June 2025
from abc import ABC, abstractmethod

class AbstractBase1(ABC):
    @abstractmethod
    def method_1_p(self):
        pass

class Encapsulated1(AbstractBase1):
    def __init__(self):
        self.__value_1 = 508

    def method_1_p(self):
        return self.__value_1

    def get_value_1(self):
        return self.__value_1

    def set_value_1(self, value):
        self.__value_1 = value

obj1 = Encapsulated1()
obj1.get_value_1()
508
from abc import ABC …

Category: basics

Read More

Python Arrays Dictionaries

Mon 30 June 2025
# Cell 1 - Python Arrays
arr = [1, 2, 3, 4, 5]
print(arr)
[1, 2, 3, 4, 5]
# Cell 2 - Python Arrays
arr = list(range(10))
print(arr)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# Cell 3 - Python Arrays
arr = list(range(15))
print(arr)
[0, 1, 2 …

Category: basics

Read More

Python Encoding Hashing

Mon 30 June 2025
text = 'icjoksiay'
encoding = text.encode('utf-8')
b64 = base64.b64encode(encoding)
print(b64)
decoded = base64.b64decode(b64).decode('utf-8')
print(decoded)
---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

Cell In[1], line 3
      1 text = 'icjoksiay'
      2 encoding = text.encode('utf-8')
----> 3 b64 = base64.b64encode(encoding)
      4 print(b64)
      5 decoded = base64 …

Category: basics

Read More

Python If Else Elif

Mon 30 June 2025
a = 15
b = 34
if a > b:
    print('a is greater')
elif a == b:
    print('a is equal to b')
else:
    print('b is greater')
b is greater
a = 54
b = 43
if a > b:
    print('a is greater')
elif a == b:
    print('a is equal to b')
else:
    print …

Category: basics

Read More

Python Libraries

Mon 30 June 2025
# Example 0 using numpy library
import numpy as np
print(np.array([0, 1, 2]).mean())
# Example 1 using pandas library
import pandas as pd
df = pd.DataFrame({'A': [1, 2]})
print(df)
# Example 2 using matplotlib library
import matplotlib.pyplot as plt
plt.plot([2, 3]); plt.show()
# Example …

Category: basics

Read More

Python Map Threading Generators Decorators Regex

Mon 30 June 2025
# Cell 1 - map

nums_1 = list(range(2))
squared_1 = list(map(lambda x: x ** 2, nums_1))
print("Cell 1 - map")
print("Input:", nums_1)
print("Squared:", squared_1)
Cell 1 - map
Input: [0, 1]
Squared: [0, 1]
# Cell 2 - map

nums_2 = list(range(3))
squared_2 = list(map(lambda x: x ** 2, nums_2))
print …

Category: basics

Read More

Python Metaclasses

Mon 30 June 2025
class Meta1(type):
    def __new__(cls, name, bases, dct):
        dct['meta_id'] = 1
        return super().__new__(cls, name, bases, dct)

class ClassWithMeta1(metaclass=Meta1):
    def show_meta_id(self):
        return self.meta_id

obj1 = ClassWithMeta1()
obj1.show_meta_id()
class Meta2(type):
    def __new__(cls, name, bases, dct):
        dct['meta_id'] = 2
        return super().__new__(cls, name …

Category: basics

Read More
Page 3 of 4

« Prev Next »