SlideShare a Scribd company logo
Introduction to Python
Why’N’How 3/19/2020
Jay Patel
Outline
• What is python?
• Why use python?
• How to use python?
• IDE
• Basic types
• Containers
• Basic control flow
• Scientific Python
• Questions?
Outline
• What is python?
• Why use python?
• How to use python?
• IDE
• Basic types
• Containers
• Basic control flow
• Scientific Python
• Questions?
What is Python?
• Interpreted (i.e. non-compiled), high-level programming language
• Compiler translates to source code to machine code before executing script
• Interpreter executes source code directly without prior compilation
• Open-source (free) and community driven
Outline
• What is python?
• Why use python?
• How to use python?
• IDE
• Basic types
• Containers
• Basic control flow
• Scientific Python
• Questions?
Why use Python?
• PROs:
• Designed to be intuitive and easy to program in (without sacrificing power)
• Open source, with a large community of packages and resources
• One of the most commonly used programming languages in the world
• “Tried and True” language that has been in development for decades
• High quality visualizations
• Runs on most operating systems and platforms
• CONs:
• Slower than “pure” (i.e. compiled) languages like C++
• Smaller/specialized packages might not be well tested / maintained
Outline
• What is python?
• Why use python?
• How to use python?
• IDE
• Basic types
• Containers
• Basic control flow
• Scientific Python
• Questions?
How to use Python
• Install python 3 distribution for your system
• Note: Python 2.7 is no longer maintained and you should do your best to
transition all old code to python 3!
• Install useful dependencies
• pip install numpy, matplotlib, scipy, nibabel, pandas, sklearn, …
• Download an IDE of your choice
• Visual Studio Code
• https://stackoverflow.com/questions/81584/what-ide-to-use-for-python
• Or run interactively in a Jupyter notebook
IDE
Outline
• What is python?
• Why use python?
• How to use python?
• IDE
• Basic types
• Containers
• Basic control flow
• Scientific Python
• Questions?
Types Basic Operations
• Numbers
• Integer
• Float
• Complex
• Boolean
• String
• Operators (non-exhaustive list)
• + #addition
• - #subtraction
• * #multiplication
• ** # power
• % # modulus
• “in” # check if element is in container
• Functions
• (Custom) operations that take one or
more pieces of data as arguments
• len(‘world’)
• Methods
• Functions called directly off data using
the “.” operator
• ‘Hello World”.split()
Examples: Numerical types
Examples: Booleans and Strings
Variable Assignment
Outline
• What is python?
• Why use python?
• How to use python?
• IDE
• Basic types
• Containers
• Basic control flow
• Scientific Python
• Questions?
Data Containers (aka Objects)
• Lists (mutable set of objects)
• var = ['one', 1, 1.0]
• Tuples (immutable set of objects)
• var = ('one', 1, 1.0)
• Dictionaries (hashing arbitrary key names to values)
• var = {'one': 1, 'two': 2, 1: 'one', 2: 'two’}
• Etc.
• Each of the above has its own set of methods
When to use one container over another
• Lists
• If you need to append/insert/remove data from a collection of (arbitrary
typed) data
• Tuples
• If you are defining a constant set of values (and then not change it), iterating
over a tuple is faster than iterating over a list
• Dictionaries
• If you need a key:value pairing structure for your dataset (i.e. searching for a
persons name (a key) will provide their phone number (a value))
Indexing through Containers
Scripting vs Functions vs Object Oriented
Approach
Outline
• What is python?
• Why use python?
• How to use python?
• IDE
• Basic types
• Containers
• Basic control flow
• Scientific Python
• Questions?
Basic Control Flow: Conditional Statements
• Use if-elif-else statements to perform certain actions only if they
meet the specified condition
Basic Control Flow: Loops
• Use to iterate over a container
List Comprehension
• Pythonic way to compress loops into a single line
• Slight speed gain to using list comprehension
• Normal loop syntax:
• For item in list:
if conditional:
expression
• List comprehension syntax:
• [expression for item in list if conditional]
List Comprehension
Variable Naming Conventions
• Very important to name your variables properly
• Helps others read your code (and helps you read your own code too!)
• Will help mitigate issues with variable overwriting/overloading
Style Conventions
• PEP8 – Style Guide for Python Code
• https://www.python.org/dev/peps/pep-0008/
• Extremely thorough resource on how to standardize your coding style
• Covers:
• Proper indentation, variable naming, commenting, documentation, maximum
line lengths, imports, etc.
Outline
• What is python?
• Why use python?
• How to use python?
• IDE
• Basic types
• Containers
• Basic control flow
• Scientific Python
• Questions?
Scientific Python
• For high efficiency, scientific computation and visualization, need to
install external packages
• NumPy
• Pandas
• Matplotlib
• SciPy
• These packages (among countless others like sympy, scikit-image,
scikit-learn, h5py, nibabel, etc.) will enable you to process high
dimensional data much more efficiently than possible using base
python
NumPy: N-dimensional arrays
• Specifically designed for efficient/fast computation
• Should be used in lieu of lists/arrays if working with entirely numeric
data
• Matlab users -> https://docs.scipy.org/doc/numpy/user/numpy-for-
matlab-users.html
• Extremely comprehensive resource comparing matlab syntax to numpy/scipy
NumPy: creating arrays
NumPy: Copies vs. Views
• Views are created by slicing through an array
• This does not create a new array in memory
• Instead, the same memory address is shared by the original array and new
sliced view
• Changing data on the view will change the original array!
• Use the copy function to copy an array to a completely new location
in memory
NumPy: Copies vs. Views
NumPy: reductions across specific dimensions
• Same applies for most numpy functions
• np.mean, np.argmax, np.argmin, np.min, np.max, np.cumsum, np.sort, etc.
Other useful Scientific Python packages
• Pandas
• Powerful data analysis and manipulation tool
• Matplotlib
• Matlab style plotting
• Scipy
• Works with NumPy to offer highly efficient matrix processing functions (i.e.
signal processing, morphologic operations, statistics, linear algebra, etc.)
• Nibabel
• Efficient loading/saving of NifTI format volumes
• …
Making Pandas DataFrame
Filtering DataFrame
Visualizations in Python
• Matplotlib is the standard
plotting library and works
very similarly to Matlab
Visualizations in Python
Visualizations in Python
Visualizations in Python: Pandas DataFrame
Visualizations in Python: Pandas DataFrame
Visualizations in Python: Pandas DataFrame
Normal overlapping histogram Stacked histogram for easier viewing
NifTI volume processing
• NifTI is a very common medical imaging format
• NifTI strips away all patient information usually in dicom header making it an
excellent format for data processing
• NiBabel package to load/save as nifti
NifTI volume processing
NifTI volume processing
Parallelizing Operations
• If processing of patients can be done independently of each other,
want to parallelize operation across CPUs to maximize efficiency
Viewing 3D NumPy arrays in Python
Simple machine learning with scikit-learn
• Sklearn contains machine learning implementations
• Regressions (linear, logistic)
• Classification (Random Forest, SVM)
• Dimensionality reduction (PCA)
• Clustering (k-means)
• Etc.
Linear Regression to predict Diabetes
Linear Regression to predict Diabetes
Outline
• What is python?
• Why use python?
• How to use python?
• IDE
• Basic types
• Containers
• Basic control flow
• Scientific Python
• Questions?
Thanks for listening!
• Questions?

More Related Content

Similar to Introduction_to_Python.pptx

Python presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, BiharPython presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, Bihar
UttamKumar617567
 
Pa2 session 1
Pa2 session 1Pa2 session 1
Pa2 session 1
aiclub_slides
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Django
solutionstreet
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Muralidharan Deenathayalan
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Muralidharan Deenathayalan
 
Intro to Python for C# Developers
Intro to Python for C# DevelopersIntro to Python for C# Developers
Intro to Python for C# Developers
Sarah Dutkiewicz
 
Basics of python programming
Basics of python programmingBasics of python programming
Basics of python programming
Aditi Bhushan
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
TamalSengupta8
 
Raspberry using Python Session 1
Raspberry using Python Session 1Raspberry using Python Session 1
Raspberry using Python Session 1
Mohamed Abd Ela'al
 
Python ml
Python mlPython ml
Python ml
Shubham Sharma
 
prakash ppt (2).pdf
prakash ppt (2).pdfprakash ppt (2).pdf
prakash ppt (2).pdf
ShivamKS4
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
Metosin Oy
 
Python programming lab 23
Python programming lab 23Python programming lab 23
Python programming lab 23
profbnk
 
Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"
Fwdays
 
Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...
Danny Mulligan
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
Ahmet Bulut
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask Training
JanBask Training
 
Introduction to Python Programming
Introduction to Python Programming Introduction to Python Programming
Introduction to Python Programming
Md. Shafiuzzaman Hira
 

Similar to Introduction_to_Python.pptx (20)

Python presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, BiharPython presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, Bihar
 
Pa2 session 1
Pa2 session 1Pa2 session 1
Pa2 session 1
 
Python
PythonPython
Python
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Django
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Intro to Python for C# Developers
Intro to Python for C# DevelopersIntro to Python for C# Developers
Intro to Python for C# Developers
 
Basics of python programming
Basics of python programmingBasics of python programming
Basics of python programming
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
 
Raspberry using Python Session 1
Raspberry using Python Session 1Raspberry using Python Session 1
Raspberry using Python Session 1
 
Python ml
Python mlPython ml
Python ml
 
prakash ppt (2).pdf
prakash ppt (2).pdfprakash ppt (2).pdf
prakash ppt (2).pdf
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
Python programming lab 23
Python programming lab 23Python programming lab 23
Python programming lab 23
 
Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"
 
Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask Training
 
Introduction to Python Programming
Introduction to Python Programming Introduction to Python Programming
Introduction to Python Programming
 

Recently uploaded

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

Introduction_to_Python.pptx

  • 2. Outline • What is python? • Why use python? • How to use python? • IDE • Basic types • Containers • Basic control flow • Scientific Python • Questions?
  • 3. Outline • What is python? • Why use python? • How to use python? • IDE • Basic types • Containers • Basic control flow • Scientific Python • Questions?
  • 4. What is Python? • Interpreted (i.e. non-compiled), high-level programming language • Compiler translates to source code to machine code before executing script • Interpreter executes source code directly without prior compilation • Open-source (free) and community driven
  • 5. Outline • What is python? • Why use python? • How to use python? • IDE • Basic types • Containers • Basic control flow • Scientific Python • Questions?
  • 6. Why use Python? • PROs: • Designed to be intuitive and easy to program in (without sacrificing power) • Open source, with a large community of packages and resources • One of the most commonly used programming languages in the world • “Tried and True” language that has been in development for decades • High quality visualizations • Runs on most operating systems and platforms • CONs: • Slower than “pure” (i.e. compiled) languages like C++ • Smaller/specialized packages might not be well tested / maintained
  • 7. Outline • What is python? • Why use python? • How to use python? • IDE • Basic types • Containers • Basic control flow • Scientific Python • Questions?
  • 8. How to use Python • Install python 3 distribution for your system • Note: Python 2.7 is no longer maintained and you should do your best to transition all old code to python 3! • Install useful dependencies • pip install numpy, matplotlib, scipy, nibabel, pandas, sklearn, … • Download an IDE of your choice • Visual Studio Code • https://stackoverflow.com/questions/81584/what-ide-to-use-for-python • Or run interactively in a Jupyter notebook
  • 9. IDE
  • 10. Outline • What is python? • Why use python? • How to use python? • IDE • Basic types • Containers • Basic control flow • Scientific Python • Questions?
  • 11. Types Basic Operations • Numbers • Integer • Float • Complex • Boolean • String • Operators (non-exhaustive list) • + #addition • - #subtraction • * #multiplication • ** # power • % # modulus • “in” # check if element is in container • Functions • (Custom) operations that take one or more pieces of data as arguments • len(‘world’) • Methods • Functions called directly off data using the “.” operator • ‘Hello World”.split()
  • 15. Outline • What is python? • Why use python? • How to use python? • IDE • Basic types • Containers • Basic control flow • Scientific Python • Questions?
  • 16. Data Containers (aka Objects) • Lists (mutable set of objects) • var = ['one', 1, 1.0] • Tuples (immutable set of objects) • var = ('one', 1, 1.0) • Dictionaries (hashing arbitrary key names to values) • var = {'one': 1, 'two': 2, 1: 'one', 2: 'two’} • Etc. • Each of the above has its own set of methods
  • 17. When to use one container over another • Lists • If you need to append/insert/remove data from a collection of (arbitrary typed) data • Tuples • If you are defining a constant set of values (and then not change it), iterating over a tuple is faster than iterating over a list • Dictionaries • If you need a key:value pairing structure for your dataset (i.e. searching for a persons name (a key) will provide their phone number (a value))
  • 19. Scripting vs Functions vs Object Oriented Approach
  • 20. Outline • What is python? • Why use python? • How to use python? • IDE • Basic types • Containers • Basic control flow • Scientific Python • Questions?
  • 21. Basic Control Flow: Conditional Statements • Use if-elif-else statements to perform certain actions only if they meet the specified condition
  • 22. Basic Control Flow: Loops • Use to iterate over a container
  • 23. List Comprehension • Pythonic way to compress loops into a single line • Slight speed gain to using list comprehension • Normal loop syntax: • For item in list: if conditional: expression • List comprehension syntax: • [expression for item in list if conditional]
  • 25. Variable Naming Conventions • Very important to name your variables properly • Helps others read your code (and helps you read your own code too!) • Will help mitigate issues with variable overwriting/overloading
  • 26. Style Conventions • PEP8 – Style Guide for Python Code • https://www.python.org/dev/peps/pep-0008/ • Extremely thorough resource on how to standardize your coding style • Covers: • Proper indentation, variable naming, commenting, documentation, maximum line lengths, imports, etc.
  • 27. Outline • What is python? • Why use python? • How to use python? • IDE • Basic types • Containers • Basic control flow • Scientific Python • Questions?
  • 28. Scientific Python • For high efficiency, scientific computation and visualization, need to install external packages • NumPy • Pandas • Matplotlib • SciPy • These packages (among countless others like sympy, scikit-image, scikit-learn, h5py, nibabel, etc.) will enable you to process high dimensional data much more efficiently than possible using base python
  • 29. NumPy: N-dimensional arrays • Specifically designed for efficient/fast computation • Should be used in lieu of lists/arrays if working with entirely numeric data • Matlab users -> https://docs.scipy.org/doc/numpy/user/numpy-for- matlab-users.html • Extremely comprehensive resource comparing matlab syntax to numpy/scipy
  • 31. NumPy: Copies vs. Views • Views are created by slicing through an array • This does not create a new array in memory • Instead, the same memory address is shared by the original array and new sliced view • Changing data on the view will change the original array! • Use the copy function to copy an array to a completely new location in memory
  • 33. NumPy: reductions across specific dimensions • Same applies for most numpy functions • np.mean, np.argmax, np.argmin, np.min, np.max, np.cumsum, np.sort, etc.
  • 34. Other useful Scientific Python packages • Pandas • Powerful data analysis and manipulation tool • Matplotlib • Matlab style plotting • Scipy • Works with NumPy to offer highly efficient matrix processing functions (i.e. signal processing, morphologic operations, statistics, linear algebra, etc.) • Nibabel • Efficient loading/saving of NifTI format volumes • …
  • 37. Visualizations in Python • Matplotlib is the standard plotting library and works very similarly to Matlab
  • 40. Visualizations in Python: Pandas DataFrame
  • 41. Visualizations in Python: Pandas DataFrame
  • 42. Visualizations in Python: Pandas DataFrame Normal overlapping histogram Stacked histogram for easier viewing
  • 43. NifTI volume processing • NifTI is a very common medical imaging format • NifTI strips away all patient information usually in dicom header making it an excellent format for data processing • NiBabel package to load/save as nifti
  • 46. Parallelizing Operations • If processing of patients can be done independently of each other, want to parallelize operation across CPUs to maximize efficiency
  • 47. Viewing 3D NumPy arrays in Python
  • 48. Simple machine learning with scikit-learn • Sklearn contains machine learning implementations • Regressions (linear, logistic) • Classification (Random Forest, SVM) • Dimensionality reduction (PCA) • Clustering (k-means) • Etc.
  • 49.
  • 50. Linear Regression to predict Diabetes
  • 51. Linear Regression to predict Diabetes
  • 52. Outline • What is python? • Why use python? • How to use python? • IDE • Basic types • Containers • Basic control flow • Scientific Python • Questions?

Editor's Notes

  1. This will create a gui that lets your slice through your array. However, much easier to load into an external platform such as Slicer3D