Python for Science and Engineering: a presentation to A*STAR and the Singapore Computational Sciences Club, Edward Schofield, Python Charmers, June 2011
An introduction to Python in science and engineering.
The presentation was given by Dr Edward Schofield of Python Charmers (www.pythoncharmers.com) to A*STAR and the Singapore Computational Sciences Club in June 2011.
** Python Certification Training: https://www.edureka.co/python **
This Edureka tutorial on "Python Tutorial for Beginners" (Python Blog Series: https://goo.gl/nKQJHQ) covers all the basics of Python. It includes python programming examples, so try it yourself and mention in the comments section if you have any doubts. Following are the topics included in this PPT:
Introduction to Python
Reasons to choose Python
Installing and running Python
Development Environments
Basics of Python Programming
Starting with code
Python Operators
Python Lists
Python Tuples
Python Sets
Python Dictionaries
Conditional Statements
Looping in Python
Python Functions
Python Arrays
Classes and Objects (OOP)
Conclusion
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
** Python Certification Training: https://www.edureka.co/python **
This Edureka tutorial on "Python Tutorial for Beginners" (Python Blog Series: https://goo.gl/nKQJHQ) covers all the basics of Python. It includes python programming examples, so try it yourself and mention in the comments section if you have any doubts. Following are the topics included in this PPT:
Introduction to Python
Reasons to choose Python
Installing and running Python
Development Environments
Basics of Python Programming
Starting with code
Python Operators
Python Lists
Python Tuples
Python Sets
Python Dictionaries
Conditional Statements
Looping in Python
Python Functions
Python Arrays
Classes and Objects (OOP)
Conclusion
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
The present condition in Industry is that they are using the crane system to carry the parcels from one place to another, including harbors. Some times the lifting of big weights may cause the breakage of lifting materials and will cause damage to the parcels too. Application of the proposed system is for industries. The robot movement depends on the track. Use of this robot is to transport the materials from one place to another place in the industry.
A robot is a machine designed to execute one or more tasks repeatedly, with speed and precision. There are as many different types of robots as there are tasks for them to perform. A robot can be controlled by a human operator, sometimes from a great distance. In such type of applications wireless communication is more important.
In robotic applications, generally we need a remote device to control. If we use IR remote device, it is just limited to meters distance and also if any obstacle is in between its path then there will be no communication. If we consider, RF modules for remote operations there is no objection whether an obstacle is present in its path. So that it is very helpful to control robot.
RF modules itself can generates its carrier frequency which is around 2.4 GHz. We need to generate serial data using micro controller and fed to the RF transmitting module. On other side RF receiver receives sent data as RF signals and given to another micro controller. Here, RF receiver itself demodulates the data from carrier signal and generate serial data as output.
Industrial robots play an increasing role in modern production and assembly facilities. The different types of robot available and their configuration are discussed. Examples of typical uses in sectors of the engineering industry are also identified.
더 많은 샘플코드는 아래 주소에서 보실 수 있습니다.
https://github.com/KennethanCeyer/pycon-kr-2017/blob/master/README-KR.md
파이썬으로 개발을 진행할 때
메모리가 넘쳐흐르거나 프로세스 진행 순서가 엉망인 경험 없으세요?
리액티브 프로그래밍은 복잡한 데이터 흐름을 새로운 관점에서 쉽게 정의하고 재활용 할 수 있도록 도와줍니다.
또한 제너레이터와 코루틴은 거대한 데이터 스트림을 가볍게 하이파이브하며 여러분이 원하는대로 처리해줄 수 있게 설계되어 있습니다. 물론 처리시간도 늘어나지 않으면서요!
다가오는 파이콘 한국 2017, 13일 일요일 점심에 여러분에게 앞서 말한 기능을 이용하여 여러분의 코드를 조금 더 효율적으로 짜실 수 있는 노하우를 공유드리고자 합니다.
Presentation for a lecture in the doctoral series at Stefan cel Mare University, Suceava, Romania, May 2009.
Aim was to show current generation the rich history of computer hardarware and that many of the recent innovations in CPU design have their origins in designs of teh 50s and 60s.
The present condition in Industry is that they are using the crane system to carry the parcels from one place to another, including harbors. Some times the lifting of big weights may cause the breakage of lifting materials and will cause damage to the parcels too. Application of the proposed system is for industries. The robot movement depends on the track. Use of this robot is to transport the materials from one place to another place in the industry.
A robot is a machine designed to execute one or more tasks repeatedly, with speed and precision. There are as many different types of robots as there are tasks for them to perform. A robot can be controlled by a human operator, sometimes from a great distance. In such type of applications wireless communication is more important.
In robotic applications, generally we need a remote device to control. If we use IR remote device, it is just limited to meters distance and also if any obstacle is in between its path then there will be no communication. If we consider, RF modules for remote operations there is no objection whether an obstacle is present in its path. So that it is very helpful to control robot.
RF modules itself can generates its carrier frequency which is around 2.4 GHz. We need to generate serial data using micro controller and fed to the RF transmitting module. On other side RF receiver receives sent data as RF signals and given to another micro controller. Here, RF receiver itself demodulates the data from carrier signal and generate serial data as output.
Industrial robots play an increasing role in modern production and assembly facilities. The different types of robot available and their configuration are discussed. Examples of typical uses in sectors of the engineering industry are also identified.
더 많은 샘플코드는 아래 주소에서 보실 수 있습니다.
https://github.com/KennethanCeyer/pycon-kr-2017/blob/master/README-KR.md
파이썬으로 개발을 진행할 때
메모리가 넘쳐흐르거나 프로세스 진행 순서가 엉망인 경험 없으세요?
리액티브 프로그래밍은 복잡한 데이터 흐름을 새로운 관점에서 쉽게 정의하고 재활용 할 수 있도록 도와줍니다.
또한 제너레이터와 코루틴은 거대한 데이터 스트림을 가볍게 하이파이브하며 여러분이 원하는대로 처리해줄 수 있게 설계되어 있습니다. 물론 처리시간도 늘어나지 않으면서요!
다가오는 파이콘 한국 2017, 13일 일요일 점심에 여러분에게 앞서 말한 기능을 이용하여 여러분의 코드를 조금 더 효율적으로 짜실 수 있는 노하우를 공유드리고자 합니다.
Presentation for a lecture in the doctoral series at Stefan cel Mare University, Suceava, Romania, May 2009.
Aim was to show current generation the rich history of computer hardarware and that many of the recent innovations in CPU design have their origins in designs of teh 50s and 60s.
The basics of Python are rather straightforward. In a few minutes you can learn most of the syntax. There are some gotchas along the way that might appear tricky. This talk is meant to bring programmers up to speed with Python. They should be able to read and write Python.
Each month, join us as we highlight and discuss hot topics ranging from the future of higher education to wearable technology, best productivity hacks and secrets to hiring top talent. Upload your SlideShares, and share your expertise with the world!
Not sure what to share on SlideShare?
SlideShares that inform, inspire and educate attract the most views. Beyond that, ideas for what you can upload are limitless. We’ve selected a few popular examples to get your creative juices flowing.
Similar to Python for Science and Engineering: a presentation to A*STAR and the Singapore Computational Sciences Club, Edward Schofield, Python Charmers, June 2011
What is Python? (Silicon Valley CodeCamp 2015)wesley chun
Slide deck for the 45-60-minute introduction to Python session talk delivered at Silicon Valley CodeCamp 2015: https://www.siliconvalley-codecamp.com/Session/2015/what-is-python
ABSTRACT
Python is an agile object-oriented programming language that continues to build momentum. It can do everything Java, C/C++/C#, Ruby, PHP, and Perl can do, but it's also fun & intuitive! Enjoy coding as fast as you think with a simple yet robust syntax that encourages group collaboration. It is known for several popular web frameworks, including Django (Python's equivalent to Ruby on Rails), Pyramid, and web2py. There is also Google App Engine, where Python was the first supported runtime. Users supporting Zope, Plone, Trac, and Mailman will also benefit from knowing some Python. Python can do XML/ReST/XSLT, multithreading, SQL/databases, GUIs, hardcore math/science, Internet client/server systems & networking (heard of Twisted?), GIS/ESRI, QA/test, automation frameworks, plus system administration tasks too! On the education front, it's a great tool to teach programming with (especially those who have done Scratch or Tynker already) as well as a solid (first) language to learn for non-programmers and other technical staff. Finally, if Python doesn't do what you want, you can extend it in C/C++, Java, or C# (even VB.NET)! Have you noticed the huge growth in the number of jobs on Monster & Dice that list Python as a desired skill? Come find out why Google, Yahoo!, Disney, Cisco, YouTube, LinkedIn, Yelp, LucasFilm/ILM, Pixar, NASA, Ubuntu, Bank of America, and Red Hat all use Python!
The following PPT is an Introduction to Python as a Programming Language and its Applications. It covers all the basic info about python and its applications. This is an interactive presentation created using PowerPoint Online.
Travis Oliphant "Python for Speed, Scale, and Science"Fwdays
Python is sometimes discounted as slow because of its dynamic typing and interpreted nature and not suitable for scale because of the GIL. But, in this talk, I will show how with the help of talented open-source contributors around the world, we have been able to build systems in Python that are fast and scalable to many machines and how this has helped Python take over Science.
Vision Academy is a well known Computer Training Institute in Hadapsar Pune from 2005.This institute was started by its visionary director Mr Sachin Zurange. Mr Sachin Zurange was completed MSc(Scientific Computing) From Interdisciplinary School Of Scientific Computing, University of Pune. It also clear SET exam in May 2018. We provides BCS, BCA, BBA(Comp.App), MCS, MCA, Dip(Comp), BE(Comp/IT) Coaching Classes in Hadapsar Pune. We mainly impart training in programming languages C,C++, Java, Advanced Java, Php, Phyton, .NET,HTML, Java Script, jQuery, Angular Js. Database Languages such as Oracle, Postgres, Mysql, SQL Server & focus on key subjects like Data Structure, Operating System,Rdbms. We provides career oriented programs in Web Design, WordPress, Digital Marketing courses. More then 10,000 students was trained from Vision Academy. We provide 100% practical oriented training program with 100% job placement.
Vision Academy’s Python Certification Training not only focuses on fundamentals of Python, Statistics and Machine Learning but also helps one gain expertise in applied Data Science at scale using Python. The training is a step by step guide to Python and Data Science with extensive hands on.
Vision Academe Pune is a leading institute in Pune conducting training programs for various software fields & provides certification for both individuals and organizations.Training Institute Pune is subsidiary of Optimized Infotech which offers IT services and training.
The Vision Phyton Institute Hands Over You The Best phyton Course In Pune. With 12 Years of Proficiency In Ecommerce, Phyton, Block Chain, Big Data, Data Science, and Many More. Trained Over 5000+ Placed Phyton . With The Help Of Our Highly Qualified Experienced Faculty Members And there Endless Efforts to bring the best out of every Student With us. As We provide Relevant Information, Data From Various Experts With Additional Reference Content, And Unconditional Practical Knowledge.
Vision Academy is a well known Computer Training Institute in Hadapsar Pune from 2005.This institute was started by its visionary director Mr Sachin Zurange. Mr Sachin Zurange was completed MSc(Scientific Computing) From Interdisciplinary School Of Scientific Computing, University of Pune. It also clear SET exam in May 2018. We provides BCS, BCA, BBA(Comp.App), MCS, MCA, Dip(Comp), BE(Comp/IT) Coaching Classes in Hadapsar Pune. We mainly impart training in programming languages C,C++, Java, Advanced Java, Php, Phyton, .NET,HTML, Java Script, jQuery, Angular Js. Database Languages such as Oracle, Postgres, Mysql, SQL Server & focus on key subjects like Data Structure, Operating System,Rdbms. We provides career oriented programs in Web Design, WordPress, Digital Marketing courses. More then 10,000 students was trained from Vision Academy. We provide 100% practical oriented training program with 100% job placement.
Similar to Python for Science and Engineering: a presentation to A*STAR and the Singapore Computational Sciences Club, Edward Schofield, Python Charmers, June 2011 (20)
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Python for Science and Engineering: a presentation to A*STAR and the Singapore Computational Sciences Club, Edward Schofield, Python Charmers, June 2011
1. Python for Science
and Engineering Dr Edward Schofield
A*STAR / Singapore Computational Sciences Club Seminar
June 14, 2011
2. Scientific programming in 2011
Most scientists and engineers are:
programming for 50+% of their work time (and rising)
self-taught programmers
using inefficient programming practices
using the wrong programming languages: C++,
FORTRAN, C#, PHP, Java, ...
4. Ed's story:
How I found Python
PhD in statistical pattern recognition: 2001-2006
Needed good tools for my research!
Discovered Python in 2002 after frustration with C++, Matlab,
Java, Perl
Contributed to NumPy and SciPy:
maxent, sparse matrices, optimization, Monte Carlo, etc.
Managed six releases of SciPy in 2005-6
9. Python’s standard library
data types strings networking threads
operating
compression GUI arguments
system
complex
CGI FTP cryptography
numbers
testing multimedia databases CSV files
calendar email XML serialization
10. What is an efficient
programming language?
Native Python code
executes 10x more slowly
than C and FORTRAN
11. Would you build a racing car ...
... to get to Kuala Lumpur ASAP?
12. Date Cost per GFLOPS (US $) Technology
1961 US $1.1 trillion 17 million IBM 1620s
1984 US $15,000,000 Cray X-MP
Two 16-CPU clusters of
1997 US $30,000
Pentiums
2000, Apr $1000 Bunyip Beowulf cluster
2003, Aug $82 KASY0
2007, Mar $0.42 Ambric AM2045
2009, Sep $0.13 ATI Radeon R800
Source: Wikipedia: “FLOPS”
23. Languages used at CSIRO
Python Fortran Java
Matlab C VB.net
IDL C++ R
Perl C# +5-10 others!
24. Which language do I choose?
A different language for each task?
A language you know?
A language others in your team are using: support and help?
25. Python Matlab
Interpreted Yes Yes
Powerful data input/output Yes Yes
Great plotting Yes Yes
General-purpose language Powerful Limited
Cost Free $$$
Open source Yes No
26. Python C++
Powerful Yes Yes
Portable Yes In theory
Standard libraries Vast Limited
Easy to write and maintain Yes No
Easy to learn Yes No
27. Python C
Fast to write Yes No
Good for embedded systems, device
No Yes
drivers and operating systems
Good for most other high-level tasks Yes No
Standard library Vast Limited
28. Python Java
Powerful, well-designed language Yes Yes
Standard libraries Vast Vast
Easy to learn Yes No
Code brevity Short Verbose
Easy to write and maintain Yes Okay
29. Open source
Python is open source software
Benefits:
No vendor lock-in
Cross-platform
Insurance against bugs in the platform
Free
31. Python success stories (2)
Aerospace:
NASA
Research:
universities worldwide ...
Others:
YouTube, Reddit, BitTorrent, Civilization IV,
32. Industrial Light & Magic
Python spread from
scripting to the entire
production pipeline
Numerous reviews since
1996: Python is still the
best tool for them
33. United Space Alliance
A common sentiment:
“We achieve immediate functioning code so much faster in
Python than in any other language that it’s staggering.”
- Robin Friedrich, Senior Project Engineer
34. Case study: air-traffic control
Eric Newton, “Python for
Critical Applications”: http://
metaslash.com/brochure/
recall.html
Metaslash, Inc: 1999 to 2001
Mission-critical system for
air-traffic control
Replicated, fault-tolerant
data storage
35. Case study: air-traffic control
Python prototype -> C++ implementation -> Python again
Why?
C++ dependencies were buggy
C++ threads, STL were not portable enough
Python’s advantages over C++
More portable
75% less code: more productivity, fewer bugs
36. More case studies
See http://www.python.org/about/success/ for lots more case
studies and success stories
41. NumPy
The most fundamental tool for numerical computing in
Python
Fast multi-dimensional array capability
42. What NumPy defines:
Two fundamental objects:
1. n-dimensional array
2. universal function
a rich set of numerical data types
nearly 400 functions and methods on arrays:
type conversions
mathematical
logical
43. NumPy's features
Fast. Written in C with BLAS/LAPACK hooks.
Rich set of data types
Linear algebra: matrix inversion, decompositions, …
Discrete Fourier transforms
Random number generation
Trig, hypergeometric functions, etc.
44. Elementwise array operations
Loops are mostly unnecessary
Operate on entire arrays!
>>> a = numpy.array([20, 30, 40, 50])
>>> a < 35
array([True, True, False, False], dtype=bool)
>>> b = numpy.arange(4)
>>> a - b
array([20, 29, 38, 47])
>>> b**2
array([0, 1, 4, 9])
45. Universal functions
NumPy defines 'ufuncs' that operate on entire arrays
and other sequences (hence 'universal')
Example: sin()
>>> a = numpy.array([20, 30, 40, 50])
>>> c = 10 * numpy.sin(a)
>>> c
array([ 9.12945251, -9.88031624, 7.4511316 ,
-2.62374854])
46. Array slicing
Arrays can be sliced and indexed powerfully:
>>> a = numpy.arange(10)**3
>>> a
array([ 0, 1, 8, 27, 64, 125, 216, 343,
512, 729])
>>> a[2:5]
array([ 8, 27, 64])
47. Fancy indexing
Arrays can be used as indices into other arrays:
>>> a = numpy.arange(12)**2
>>> ind = numpy.array([ 1, 1, 3, 8, 5 ])
>>> a[ind]
array([ 1, 1, 9, 64, 25])
48. Other linear algebra features
Matrix inversion: mat(A).I
Or: linalg.inv(A)
Linear solvers: linalg.solve(A, x)
Pseudoinverse: linalg.pinv(A)
49. What is SciPy?
A community
A conference
A package of scientific libraries
50. Python for scientific software
Back-end: computational work
Front-end: input / output, visualization, GUIs
Dozens of great scientific packages exist
51. Python in science (2)
NumPy: numerical / array module
Matplotlib: great 2D and 3D plotting library
IPython: nice interactive Python shell
SciPy: set of scientific libraries: sparse matrices, signal
processing, …
RPy: integration with the R statistical environment
52. Python in science (3)
Cython: C language extensions
Mayavi: 3D graphics, volumetric rendering
Nitimes, Nipype: Python tools for neuroimaging
SymPy: symbolic mathematics library
53. Python in science (4)
VPython: easy, real-time 3D programming
UCSF Chimera, PyMOL, VMD: molecular graphics
PyRAF: Hubble Space Telescope interface to RAF astronomical
data
BioPython: computational molecular biology
Natural language toolkit: symbolic + statistical NLP
Physics: PyROOT
54. The SciPy package
BSD-licensed software for maths, science,
engineering
integration signal processing sparse matrices
optimization linear algebra maximum entropy
interpolation ODEs statistics
n-dim image
FFTs scientific constants
processing
C/C++ and Fortran
clustering interpolation
integration
56. Example: fitting a model with
scipy.optimize
Task: Fit a model of the form y = a/bx sin(cx)+ε
to noisy data.
Spec:
1. Generate noisy data
2. Choose parameters (a, b, c) to minimize sum squared
errors
3. Plot the data and fitted model (next session)
57. SciPy optimisation example
import numpy
import pylab
from scipy.optimize import leastsq
def myfunc(params, x):
(a, b, c) = params
return a / (x**b) * numpy.sin(c * x)
true_params = [1.5, 0.1, 2.]
def f(x):
return myfunc(true_params, x)
def err(params, x, y): # error function
return myfunc(params, x) - y
58. SciPy optimisation example
# Generate noisy data to fit
n = 30; xmin = 0.1; xmax = 5
x = numpy.linspace(xmin, xmax, n)
y = f(x)
y += numpy.rand(len(x)) * 0.2 *
(y.max() - y.min())
v0 = [3., 1., 4.] # initial param estimate
# Fitting
v, success = leastsq(err, v0, args=(x, y), maxfev=10000)
print 'Estimated parameters: ', v
print 'True parameters: ', true_params
X = numpy.linspace(xmin, xmax, 5 * n)
pylab.plot(x, y, 'ro', X, myfunc(v, X))
pylab.show()
62. Sparse matrices
Sparse matrices are mostly zeros.
They can be symmetric or
asymmetric.
Sparsity patterns vary:
block sparse, band matrices, ...
They can be huge!
Only non-zeros are stored.
63. Sparse matrices in SciPy
SciPy supports seven sparse storage schemes
... and sparse solvers in Fortran.
64. Sparse matrix creation
To construct a 1000x1000 lil_matrix and add values:
>>> from scipy.sparse import lil_matrix
>>> from numpy.random import rand
>>> from scipy.sparse.linalg import spsolve
>>> A = lil_matrix((1000, 1000))
>>> A[0, :100] = rand(100)
>>> A[1, 100:200] = A[0, :100]
>>> A.setdiag(rand(1000))
65. Solving sparse matrix
systems
Now convert the matrix to CSR format and solve Ax=b:
>>> A = A.tocsr()
>>> b = rand(1000)
>>> x = spsolve(A, b)
# Convert it to a dense matrix and solve, and
check that the result is the same:
>>> from numpy.linalg import solve, norm
>>> x_ = solve(A.todense(), b)
# Compute norm of the error:
>>> err = norm(x - x_)
>>> err < 1e-10
True
66. Matplotlib
Great plotting package in Python
Matlab-like syntax
Great rendering: anti-aliasing etc.
Many ‘backends’: Cairo, GTK, Cocoa, PDF
Flexible output: to EPS, PS, PDF, TIFF, PNG, ...
68. Example: NumPy
vectorization
1. Use a Monte Carlo algorithm to
estimate π:
1. Generate uniform random variates (x,%y) over [0, 1].
2. Estimate π from the proportion p that land in the unit
circle.
2. Time two ways of doing this:
1. Using for loops
2. Using array operations (vectorized)
72. Python for HPC
Advantages Disadvantages
Portability Global interpreter lock
Easy scripting, glue Less control than C
Maintainability Native loops are slow
Profiling to identify hotspots
Vectorization with NumPy
73. Large data sets
Useful Python language features:
Generators, iterators
Useful packages:
Great HDF5 support from PyTables!
76. Applications of PyTables
aeronautics telecommunications
drug discovery data mining
financial analysis statistical analysis
climate prediction etc.
77. Breaking news: June 2011
PyTables Pro is now being open sourced.
Indexed searches for speed
Merging with PyTables
Working project name: NewPyTables
78. PyTables performance
OPSI indexing engine speed:
Querying 10 billion rows can take hundredths of a
second!
Target use-case:
mostly read-only or append-only data
80. Important principles
1. "Premature optimization is the root of all evil"
Don't write cryptic code just to make it more efficient!
2. 1-5% of the code takes up the vast majority of the
computing time!
... and it might not be the 1-5% that you think!
81. Checklist for efficient code
From most to least important:
1. Check: Do you really need to make it more efficient?
2. Check: Are you using the right algorithms and data
structures?
3. Check: Are you reusing pre-written libraries wherever
possible?
4. Check: Which parts of the code are expensive?
Measure, don't guess!
82. Relative efficiency gains
Exponential-order and polynomial-order speedups are
possible by choosing the right algorithm for a task.
These require the right data structures!
These dwarf 10-25x linear-order speedups from:
using lower-level languages
using different language constructs.
84. The largest Python training provider in South-East Asia
Delighted customers include:
85. Most popular course topics
Python for Programmers 3 days
Python for Scientists and Engineers 4 days
Python for Geoscientists 4 days
Python for Bioinformaticians 4 days
New courses:
Python for Financial Engineers 4 days
Python for IT Security Professionals 3 days
86. Python Charmers:
Topics of expertise
Python: beginners, advanced
Scientific data processing with Python
Software engineering with Python
Large-scale problems: HPC, huge data sets, grids
Statistics and Monte Carlo problems
87. Python Charmers:
Topics of expertise (2)
Spatial data analysis / GIS
General scripting, job control, glue
GUIs with PyQt
Integrating with other languages: R, C, C++, Fortran, ...
Web development in Django
88. How to get in touch
See PythonCharmers.com
or email us at: info@pythoncharmers.com