0% found this document useful (0 votes)
4 views15 pages

Section2 CG

Uploaded by

manarshreef8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views15 pages

Section2 CG

Uploaded by

manarshreef8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Computer Graphics

Section 2
Python Functions
• Functions are blocks of reusable code that perform a specific task.

• You can use * before the parameter name If you do not know how many
arguments will be passed into your function (collected as a tuple).
Python Functions
• You can set a default value for a parameter.
Python Functions

• Recursion in python is a technique where a function calls itself in


order to solve a problem.

• Base Case: If n is 0 or 1, the function returns 1.


• Recursive Case: If n is greater than 1, the function calls itself with n - 1
Python Classes and Objects
• A class is a blueprint for creating objects. It defines a set of
attributes and methods that the created objects will have.
• Attributes: Variables that belong to the class (like name and age in the
Dog class)
• Methods: Functions defined inside a class that operate on the attributes
(like bark and get_age).
• The __init__ method is a special
method called a constructor.
• It initializes the object’s
attributes when a new object is
created.
Python Classes and Objects

• An object is an instance of a class.


• When you create an object, you instantiate the class.
Inheritance
• Inheritance allows a new class (called a derived or child class) to inherit
attributes and methods from an existing class (called a base or parent class).
Polymorphism
• Polymorphism, means "many forms“, it allows methods with the same name
to be executed on different objects or classes.
Python NumPy
• The NumPy library in Python is a powerful tool for providing a wide range of
mathematical functions for array operations and numerical computing.
• Array dimensions:
Python NumPy
• Accessing Elements
Python NumPy Slicing
• NumPy array slicing allows you to extract specific portions of an array. It’s
similar to slicing Python lists but is more powerful.
• The basic syntax for slicing is:
array[start:stop:step/direction]
Python NumPy Slicing
• For n-dimensions arrays, slicing can be specified for each dimension:
array[ start:end:step/direction, start:end:step/direction , start:end:step/direction , … ]
Python NumPy Slicing
• Note: you don’t have to specify all dimensions if you want all elements in them.
• Example: arr[1, : , :] is the same as arr[1]
Python matplolib, numpy
Thank You

You might also like