SlideShare une entreprise Scribd logo
1  sur  53
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?

Contenu connexe

Similaire à 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, BiharUttamKumar617567
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Djangosolutionstreet
 
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 StudioMuralidharan 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 StudioMuralidharan Deenathayalan
 
Intro to Python for C# Developers
Intro to Python for C# DevelopersIntro to Python for C# Developers
Intro to Python for C# DevelopersSarah Dutkiewicz
 
Basics of python programming
Basics of python programmingBasics of python programming
Basics of python programmingAditi Bhushan
 
Raspberry using Python Session 1
Raspberry using Python Session 1Raspberry using Python Session 1
Raspberry using Python Session 1Mohamed Abd Ela'al
 
prakash ppt (2).pdf
prakash ppt (2).pdfprakash ppt (2).pdf
prakash ppt (2).pdfShivamKS4
 
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 AbstractionsMetosin Oy
 
Python programming lab 23
Python programming lab 23Python programming lab 23
Python programming lab 23profbnk
 
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 1Ahmet Bulut
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask TrainingJanBask Training
 

Similaire à 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
 

Dernier

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Dernier (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

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?

Notes de l'éditeur

  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