Classes and Objects in Python
10 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

In "Fishermen Drawing Nets", the subject matter depicts fishermen engaged in their daily activities, highlighting the significance of ______ as a cultural and economic activity.

fishing

Battiss's style in "Fishermen Drawing Nets" is characterized by simplicity and directness, focusing on capturing the essence of his subjects with economy of form and ______.

expression

The forms in "Fishermen Drawing Nets" are ______ but recognizable, with an emphasis on the human figures and their relationship to the nets and the environment.

stylized

Irma Stern's "Pondo Woman" aims to represent African culture by focusing on the subject's attire, facial features, and ______ language.

<p>body</p> Signup and view all the answers

Stern's style in "Pondo Woman" blends realism and ______, employing a combination of traditional and modern techniques to create visually striking compositions.

<p>abstraction</p> Signup and view all the answers

The possible meaning of "Pondo Woman" celebrates the beauty and dignity of African culture while reminding viewers of the importance of preserving traditional ______.

<p>customs</p> Signup and view all the answers

Gerard Sekoto's "The Song of the Pick" portrays Black South African miners engaged in labour, showcasing the rhythmic nature of work and the role of ______ in cultural expression.

<p>music</p> Signup and view all the answers

Sekoto draws inspiration from personal experiences, cultural traditions, and European modernist movements like ______, which he adapts to reflect his unique perspective as a Black artist.

<p>Van Gogh</p> Signup and view all the answers

George Pemba's "Eviction - Woman & Child" uses muted ______ to evoke a somber mood and highlight the emotional gravity of the scene.

<p>tones</p> Signup and view all the answers

Pemba was influenced by the forced removals of black families during ______, his art aimed to highlight the suffering of marginalized communities and raise awareness of injustices.

<p>apartheid</p> Signup and view all the answers

Flashcards

Subject matter of Walter Battiss - Fishermen Drawing Nets

Depicts fishermen in their daily activities along the coast of South Africa, emphasizing the significance of fishing.

Influence of indigenous symbols in "Fishermen Drawing Nets"

Incorporates indigenous symbols and motifs related to coastal life, celebrating the connection of coastal communities to the sea.

Style and technique of Walter Battiss

Battiss focuses on capturing the essence of his subjects with simplicity and directness, blending impressionistic and abstract techniques.

Possible meaning of "Fishermen"

Celebrates the resilience and resourcefulness of African coastal communities, emphasizing fishing as a way of life and sustenance.

Signup and view all the flashcards

Irma Stern's - Pondo Woman Subject Matter

Depicts a woman from the Pondo tribe of South Africa, focusing on her attire, facial features, and body language.

Signup and view all the flashcards

Indigenous/African symbols in "Pondo Woman"

Incorporates indigenous symbols and motifs such as traditional clothing, jewelry, and body adornments.

Signup and view all the flashcards

Irma Stern's style and technique

Stern's style blends realism and abstraction, employing a combination of traditional and modern techniques.

Signup and view all the flashcards

Possible meaning of "Pondo Woman"

"Pondo Woman" celebrates the beauty and dignity of African culture, reminding viewers of preserving traditional customs.

Signup and view all the flashcards

Gerard Sekoto's - The song of the pick Subject matter

Portrays Black South African miners engaged in labour, showcasing the rhythmic nature of work and role of music.

Signup and view all the flashcards

Possible meaning of "The Song of the Pick"

The artwork celebrates the resilience and cultural pride of Black South Africans, highlighting the importance of music and community in adversity.

Signup and view all the flashcards

Study Notes

Lab 7: Classes and Objects

Objectives

  • Learn to define a class with attributes and methods.
  • Learn how to create objects of a class.
  • Learn how to access attributes and call methods of an object.

Motivation

  • Classes are fundamental in object-oriented programming (OOP) for creating custom data types.
  • These types can store data (attributes) and perform actions (methods).

Classes and Objects

Defining a Class

  • A class serves as a blueprint for creating objects, defining their attributes and methods.
  • Syntax:
class ClassName:
    def __init__(self, attribute1, attribute2,...):
        self.attribute1 = attribute1
        self.attribute2 = attribute2...

    def method1(self, parameter1, parameter2,...):
        # Code for method1
        pass

    def method2(self, parameter1, parameter2,...):
        # Code for method2
        pass...
  • class: Keyword for defining a class.
  • ClassName: Name of the class, starting with a capital letter.
  • __init__: Special constructor method to initialize object attributes.
  • self: Refers to the instance of the class (the object itself).
  • attribute1, attribute2,...: Data attributes of the class.
  • method1, method2,...: Function methods of the class.

Creating Objects

  • Objects are created using the class name followed by parentheses.
  • Syntax:
object_name = ClassName(value1, value2,...)
  • object_name: Name of the object being created.
  • ClassName: Class from which the object is created.
  • value1, value2,...: Values passed to the constructor to initialize object attributes.

Accessing Attributes and Calling Methods

  • Attributes are accessed using dot notation.
object_name.attribute1  # Accessing attribute1
object_name.attribute2  # Accessing attribute2...
  • Methods are called using dot notation.
object_name.method1(parameter1, parameter2,...)  # Calling method1
object_name.method2(parameter1, parameter2,...)  # Calling method2...

Example: The Rectangle Class

  • A class to represent rectangles with attributes for width and height.
  • Includes methods to calculate area and perimeter.
  • Code:
class Rectangle:
    def __init__(self, width, height):
        self.width = width
        self.height = height

    def calculate_area(self):
        return self.width * self.height

    def calculate_perimeter(self):
        return 2 * (self.width + self.height)
  • __init__ method initializes the width and height attributes.
  • calculate_area method calculates the area.
  • calculate_perimeter method calculates the perimeter.

Creating an object and accessing attributes/methods

## Create a Rectangle object
my_rectangle = Rectangle(width=5, height=10)

## Access attributes
print("Width:", my_rectangle.width)   # Output: Width: 5
print("Height:", my_rectangle.height)  # Output: Height: 10

## Call methods
area = my_rectangle.calculate_area()
perimeter = my_rectangle.calculate_perimeter()

print("Area:", area)          # Output: Area: 50
print("Perimeter:", perimeter)  # Output: Perimeter: 30

Exercises

Exercise 1: The Circle Class

  • Attributes: radius
  • Methods:
    • __init__(self, radius): Initializes the radius attribute.
    • calculate_area(self): Calculates the area of the circle using the formula: (\pi \times \text{radius}^2).
    • calculate_circumference(self): Calculates the circumference of the circle using the formula: (2 \times \pi \times \text{radius}).
  • Code:
import math

class Circle:
    def __init__(self, radius):
        self.radius = radius

    def calculate_area(self):
        return math.pi * self.radius**2

    def calculate_circumference(self):
        return 2 * math.pi * self.radius

## Create a Circle object
my_circle = Circle(radius=7)

## Access attributes
print("Radius:", my_circle.radius)  # Output: Radius: 7

## Call methods
area = my_circle.calculate_area()
circumference = my_circle.calculate_circumference()

print("Area:", area)                 # Output: Area: 153.93804002589985
print("Circumference:", circumference) # Output: Circumference: 43.982297150257104

Exercise 2: The Student Class

  • Attributes: name, student_id, grades (a list of numbers).
  • Methods:
    • __init__(self, name, student_id): Initializes the name, student_id, and grades attributes. The grades attribute initializes as an empty list.
    • add_grade(self, grade): Adds a grade to the grades list.
    • calculate_average_grade(self): Calculates the average grade of the student.
  • Code:
class Student:
    def __init__(self, name, student_id):
        self.name = name
        self.student_id = student_id
        self.grades = []

    def add_grade(self, grade):
        self.grades.append(grade)

    def calculate_average_grade(self):
        if not self.grades:
            return 0
        return sum(self.grades) / len(self.grades)

## Create a Student object
student1 = Student(name="Alice", student_id="12345")

## Access attributes
print("Name:", student1.name)           # Output: Name: Alice
print("Student ID:", student1.student_id)  # Output: Student ID: 12345

## Call methods
student1.add_grade(85)
student1.add_grade(90)
student1.add_grade(95)

average_grade = student1.calculate_average_grade()

print("Grades:", student1.grades)          # Output: Grades: [85, 90, 95]
print("Average Grade:", average_grade)  # Output: Average Grade: 90.0

Exercise 3: The Calculator Class

  • Methods:
    • add(self, x, y): Adds two numbers and returns the result.
    • subtract(self, x, y): Subtracts two numbers and returns the result.
    • multiply(self, x, y): Multiplies two numbers and returns the result.
    • divide(self, x, y): Divides two numbers and returns the result. If the second number is zero, return "Cannot divide by zero.".
  • Code:
class Calculator:
    def add(self, x, y):
        return x + y

    def subtract(self, x, y):
        return x - y

    def multiply(self, x, y):
        return x * y

    def divide(self, x, y):
        if y == 0:
            return "Cannot divide by zero."
        return x / y

## Create a Calculator object
calc = Calculator()

## Call methods
print("Add:", calc.add(5, 3))       # Output: Add: 8
print("Subtract:", calc.subtract(5, 3))  # Output: Subtract: 2
print("Multiply:", calc.multiply(5, 3))  # Output: Multiply: 15
print("Divide:", calc.divide(5, 3))    # Output: Divide: 1.6666666666666667
print("Divide by zero:", calc.divide(5, 0)) # Output: Divide by zero: Cannot divide by zero.

Conclusion

  • Classes and objects are fundamental concepts that you have learned about in object-oriented programming.
  • Essential for writing complex and maintainable code.

Funciones vectoriales de una variable real

Introducción

  • Vector-valued functions of a real variable assign a vector to each real number.

Definición

  • A vector-valued function has the form.
  • $\vec{r}(t) = (x(t), y(t), z(t))$, where $x(t)$, $y(t)$, and $z(t)$ are real functions of the real variable $t$.

Dominio

  • The domain of $\vec{r}(t)$ includes all $t$ values for which the function is defined.
  • This is the intersection of the domains of $x(t)$, $y(t)$, and $z(t)$.

Límite

  • Limit of a vector-valued function $\vec{r}(t)$ as $t$ approaches $a$.
  • Expressed as $\lim_{t \to a} \vec{r}(t) = \vec{L}$ if and only if $\lim_{t \to a} x(t) = L_1$, $\lim_{t \to a} y(t) = L_2$, and $\lim_{t \to a} z(t) = L_3$.
  • $\vec{L} = (L_1, L_2, L_3)$.

Continuidad

  • Continuity of $\vec{r}(t)$ at $t = a$ requires:
    • $\vec{r}(a)$ be defined.
    • $\lim_{t \to a} \vec{r}(t)$ exists.
    • $\lim_{t \to a} \vec{r}(t) = \vec{r}(a)$.

Derivada

  • The derivative of $\vec{r}(t)$ is the vector-valued function $\vec{r}'(t)$.
  • Defined by $\vec{r}'(t) = \lim_{h \to 0} \frac{\vec{r}(t + h) - \vec{r}(t)}{h}$, if this limit exists.
  • Equivalent to $\vec{r}'(t) = (x'(t), y'(t), z'(t))$.

Interpretación geométrica de la derivada

  • The derivative $\vec{r}'(t)$ is a tangent vector to the curve described by $\vec{r}(t)$ at the point $\vec{r}(t)$.

Reglas de derivación

  • For differentiable vector functions $\vec{r}(t)$ and $\vec{s}(t)$, and scalar function $f(t)$.
    • $\frac{d}{dt} [\vec{r}(t) + \vec{s}(t)] = \vec{r}'(t) + \vec{s}'(t)$
    • $\frac{d}{dt} [c\vec{r}(t)] = c\vec{r}'(t)$, where $c$ is a constant.
    • $\frac{d}{dt} [f(t)\vec{r}(t)] = f'(t)\vec{r}(t) + f(t)\vec{r}'(t)$
    • $\frac{d}{dt} [\vec{r}(t) \cdot \vec{s}(t)] = \vec{r}'(t) \cdot \vec{s}(t) + \vec{r}(t) \cdot \vec{s}'(t)$
    • $\frac{d}{dt} [\vec{r}(t) \times \vec{s}(t)] = \vec{r}'(t) \times \vec{s}(t) + \vec{r}(t) \times \vec{s}'(t)$
    • $\frac{d}{dt} [\vec{r}(f(t))] = \vec{r}'(f(t))f'(t)$ (Chain Rule)

Integración

  • The integral of a vector-valued function $\vec{r}(t)$ is the vector function $\vec{R}(t)$ where $\vec{R}'(t) = \vec{r}(t)$.

Integral definida

  • The definite integral of $\vec{r}(t)$ between $a$ and $b$ is: $\qquad \int_{a}^{b} \vec{r}(t) dt = \left( \int_{a}^{b} x(t) dt, \int_{a}^{b} y(t) dt, \int_{a}^{b} z(t) dt \right)$

Longitud de arco

  • The arc length of a curve described by $\vec{r}(t)$ is:

$\qquad L = \int_{a}^{b} |\vec{r}'(t)| dt = \int_{a}^{b} \sqrt{[x'(t)]^2 + [y'(t)]^2 + [z'(t)]^2} dt$

Parametrización por longitud de arco

  • A parameterization by arc length has a unit tangent vector length of 1.

Vector tangente unitario

  • The unit tangent vector $\vec{T}(t)$ of a curve described by $\vec{r}(t)$ is: $\qquad \vec{T}(t) = \frac{\vec{r}'(t)}{|\vec{r}'(t)|}$

Vector normal principal

  • The principal normal vector $\vec{N}(t)$ of a curve described by $\vec{r}(t)$ is: $\qquad \vec{N}(t) = \frac{\vec{T}'(t)}{|\vec{T}'(t)|}$

Vector binormal

  • The binormal vector $\vec{B}(t)$ to a curve described by $\vec{r}(t)$ is defined as: $\qquad \vec{B}(t) = \vec{T}(t) \times \vec{N}(t)$

Torsión

  • Torsion $\tau(t)$ measures how quickly the curve twists out of its osculating plane.
  • Defined as: $\qquad \tau(t) = -\frac{\vec{B}'(t) \cdot \vec{N}(t)}{|\vec{r}'(t)|}$

Curvatura

  • Curvature $\kappa(t)$ measures how quickly the curve changes direction.
  • Defined as: $\qquad \kappa(t) = \frac{|\vec{T}'(t)|}{|\vec{r}'(t)|} = \frac{|\vec{r}'(t) \times \vec{r}''(t)|}{|\vec{r}'(t)|^3}$

Algorithmic Game Theory

What is Game Theory?

  • A framework for understanding interactions among multiple agents, each with their own incentives.
  • Each agent is selfish and aims to maximize their own utility.
  • Useful for designing systems acknowledging these incentives.

Examples

  • Auctions
  • Routing in Networks
  • Social Networks
  • Sponsored Search engines

Algorithmic Game Theory (AGT)

  • AGT merges Computer Science with Game Theory.
    • Computer Science: Algorithms, Data Structures, Computational Complexity, and Network Analysis.
    • Game Theory: Economic/Behavioral Models.
  • AGT centers around designing algorithms that account for strategic behavior.

Example: Selfish Routing

  • $n$ agents wanting to minimize their latency.
  • The difference between System optimum compared to User equilibrium.

Selfish Routing: Braess's Paradox

  • Adding a road to a network can actually worsen traffic flow due to selfish routing.

What is learned in AGT?

  • Solution Concepts (Equilibria):
    • Nash Equilibrium
    • Variants: Mixed, Correlated, Bayes-Nash
    • Refinements: Subgame Perfect, Perfect Bayesian
  • Price of Anarchy/Stability
  • Mechanism Design:
    • Auctions
    • Cost-Sharing
    • Voting
  • Learning in Games
  • Complexity
  • "Algorithmic Game Theory" by Nisan, Roughgarden, Tardos, and Vazirani.

Course Logistics

  • Website: Available on Canvas
    • Lecture slides
    • Homework assignments
    • Reading material

Grading

  • 60%: Homeworks
    • Mix of theory and programming
    • Submit code to Gradescope
    • Each student gets 5 late days
  • 40%: Final Project
    • Implement and evaluate a game-theoretic algorithm/solve a problem in AGT
    • Teams of 1-3 students

Prerequisites

  • Algorithms
  • Probability
  • Linear Algebra / Calculus
  • Comfortable with proofs.

What are games?

Normal-Form Games

  • A normal-form game consists of:
    • A set of $N$ players $N = {1,2,..,n}$.
    • A set $A_i$ of available actions for each player $i$.
    • A utility function $u_i : A \rightarrow \mathbb{R}$ for each player $i$, where $A = A_1 \times A_2... \times A_n$ is the set of action profiles.

Example: Prisoner's Dilemma

  • Two suspects are arrested.
  • If one confesses and the other does not, the confessor is freed and the other spends 10 years in prison.
  • If both confess, they each spend 5 years in prison.
  • If neither confesses, they each spend 1 year in prison.

Example: Prisoner's Dilemma

Utility Matrix

Player 2: Cooperate Player 2: Defect
Cooperate -1, -1 -10, 0
Defect 0, -10 -5, -5

Example: Rock-Paper-Scissors

Utility Matrix

Player 2: Rock Player 2: Paper Player 2: Scissors
Rock 0, 0 -1, 1 1, -1
Paper 1, -1 0, 0 -1, 1
Scissors -1, 1 1, -1 0, 0

Solution Concepts

What outcomes will emerge?

  • Solution concepts predict strategies and observed outcomes.

Nash Equilibrium

  • Strategy profile where no player has an incentive to unilaterally deviate.

Algèbre linéaire Cours et exercices

Marcel Berger, Professeur à l'Université Paris VII

TABLE DES MATIÈRES

  • Chapitre 1. Ensembles, relations, applications, cardinaux
    • Ensembles
    • Relations
    • Applications
    • Cardinaux
  • Chapitre 2. Espaces vectoriels
    • Définitions, exemples
    • Sous-espaces vectoriels
    • Applications linéaires
    • Produit, somme directe
    • Espaces quotients
  • Chapitre 3. Dimension finie
    • Générateurs, indépendance
    • Base, dimension
    • Applications linéaires en dimension finie
    • Rang
    • Dualité
    • Transposée
  • Chapitre 4. Matrices
    • Définitions
    • Matrices et applications linéaires
    • Matrices de passage
    • Opérations élémentaires
    • Équivalence de matrices
    • Matrices et systèmes linéaires
  • Chapitre 5. Déterminants
    • Formes multilinéaires alternées
    • Déterminant d'une famille de vecteurs
    • Déterminant d'un endomorphisme
    • Déterminant d'une matrice
    • Calculs de déterminants
  • Chapitre 6. Réduction des endomorphismes
    • Généralités
    • Polynômes d'endomorphismes
    • Valeurs propres, vecteurs propres, sous-espaces propres
    • Diagonalisation
    • Trigonalisation
    • Endomorphismes nilpotents
    • Décomposition de Dunford
    • Exponentielle d'un endomorphisme
  • Chapitre 7. Espaces euclidiens
    • Produit scalaire, norme
    • Orthogonalité
    • Adjoint d'un endomorphisme
    • Endomorphismes orthogonaux
    • Espaces hermitiens
  • Chapitre 8. Formes quadratiques
    • Généralités
    • Orthogonalité, isotropie
    • Décomposition de Gauss
    • Classification
    • Espace euclidien, espace hermitien
  • Chapitre 9. Topologie des espaces vectoriels de dimension finie
    • Généralités
    • Applications linéaires continues
    • Compacité
    • Intégration
  • Chapitre 10. Analyse numérique matricielle
    • Généralités sur les normes
    • Normes matricielles
    • Résolution des systèmes linéaires
    • Calcul des éléments propres
  • Index

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Learn to define classes with attributes/methods and create objects in Python. Classes are the base of object-oriented programming. They store data and perform actions.

More Like This

Use Quizgecko on...
Browser
Browser