SlideShare ist ein Scribd-Unternehmen logo
1 von 36
NumPy MemoryMapped Arrays May 22, 2009
A word from our sponsor

Enthought Python Distribution (EPD) MORE THAN FIFTY INTEGRATED PACKAGES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Enthought Python Distribution (EPD) Explanations, demonstrations, and tips  For subscribers to Enthought Python Distribution (EPD) and their guests.  Presenters and Panelists will include Enthought experts and other leading community members.
Enthought Training Courses Python Basics, NumPy, SciPy, Matplotlib, Traits, TraitsUI, Chaco

Upcoming Training Classes June 15 - 19, 2009 Introduction to Scientific Computing with Python  Austin, Texas July, 2009 TBA August, 2009 TBA September 21 to 25, 2009 Introduction to Scientific Computing with Python  Austin, Texas http://www.enthought.com/training/
Enthought Consulting Process Built with Python by a team of scientists, EPD provides a versatile and coherent platform for analysis and visualization .
Software Application Layers Python NumPy (Array Mathematics) SciPy (Scientific Algorithms) 3 rd  Party Libraries wxPython VTK, etc. ETS (App construction) Traits, Chaco, Mayavi, Envisage, etc. Domain Specific GUI Applications Semiconductor, Fluid Dynamics, Seismic Modeling, Financial, etc.
Shell
Chaco: Interactive Graphics
[object Object],[object Object],[object Object],[object Object],VMS – Virtual Mixing System
Multiple Plug-ins.  One Application
 
Database Access Compliance Tools Equipment Interface Scientific Algorithms UI Elements Testing Framework Scripting Interface Chaco Plotting Data Display Rich Client App (Geophysics, Finance, Etc)
NumPy
Array Data Structure
“Structured” Arrays name char[10] age  int weight double Elements of an array can be any fixed-size data structure! EXAMPLE >>> from numpy import dtype, empty # structured data format >>> fmt = dtype([('name', 'S10'), ('age', int),  ('weight', float) ]) >>> a = empty((3,4), dtype=fmt)   >>> a.itemsize 22 >>> a['name'] = [['Brad',  ,'Jill']] >>> a['age'] = [[33,  ,54]] >>> a['weight'] = [[135,  ,145]] >>> print a [[('Brad', 33, 135.0) ('Jill', 54, 145.0)]] 27 32 61 29 145.0 88.0 135.0 188.0 54 18 33 19 Jill Jennifer Susan Ron 187.0 137.0 202.0 154.0 Amy Brian George Henry 140.0 225.0 105.0 135.0 54 47 25 33 Fred John Jane Brad
Even Nested Datatypes
Nested Datatype dt = dtype([('time', np.uint64), ('size', np.uint32), ('position', [('az', np.float32), ('el', np.float32), ('region_type', np.uint8), ('region_ID', np.uint16)]), ('gain', np.uint8), ('samples', (np.int16,2048))]) data = np.fromfile(f, dtype=dt)  If you only wanted to access a part of the file  use a memory map
Virtual Memory http://en.wikipedia.org/wiki/Virtual_memory Memory mapped files are like  intentional disk-based virutal memory
Memory Mapped Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Memory Mapped Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],some_file.dat <header>  110111
 <data>  0110000001 0010010111011000 1101001001000100 1111010101000010 0010111000101011 00011110101011

memmap ,[object Object],[object Object],[object Object],filename   Name of the underlying file.  For all modes, except for 'w+', the file must already exist and contain at least the number of bytes used by the array. dtype The numpy data type used for the array.  This can be a &quot;structured&quot; dtype as well as the standard simple data types. offset Byte offset within the file to the memory used as data within the array. mode <see next slide> shape Tuple specifying the dimensions and size of each dimension in the array.  shape=(5,10) would create a 2D array with 5 rows and 10 columns. order 'C' for row major memory ordering (standard in the C programming language) and 'F' for column major memory ordering (standard in Fortran).
memmap  -- mode ,[object Object],[object Object],[object Object],mode A string indicating how the underlying file should be opened. ' r ' or ' readonly ':  Open an existing file as an array for reading. ' c ' or ' copyonwrite ':  &quot;Copy on write&quot; arrays are &quot;writable&quot; as Python arrays, but they  never  modify the underlying file. ' r+ ' or ' readwrite ':  Create a read/write array from an existing file. The file will have &quot;write through&quot; behavior where changes to the array are written to the underlying file.  Use the  flush()   method to ensure the array is synchronized with the file. ' w+ ' or ' write ':  Create the file or overwrite if it exists.  The array is filled with zeros and has &quot;write through&quot; behavior similar to 'r+'.
memmap -- write through behavior # Create a memory mapped &quot;write through&quot; file, overwriting it if it exists. In [66]: q=memmap('new_file.dat',mode='w+',shape=(2,5)) In [67]: q memmap([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], dtype=uint8) # Print out the contents of the underlying file.  Note: It # doesn't print because 0 isn't a printable ascii character. In [68]: !cat new_file.dat # Now write the ascii value for 'A' (65) into our array. In [69]: q[:] = ord('A') In [70]: q memmap([[65, 65, 65, 65, 65], [65, 65, 65, 65, 65]], dtype=uint8) # Ensure the OS has written the data to the file, and examine # the underlying file. It is full of 'A's as we hope. In [71]: q.flush() In [72]: !cat new_file.dat AAAAAAAAAA
memmap -- copy on write behavior # Create a copy-on-write memory map where the underlying file is never # modified.  The file must already exist. # This is a memory efficient way of working with data on disk as arrays but  # ensuring you never modify it. In [73]: q=memmap('new_file.dat',mode='c',shape=(2,5)) In [74]: q memmap([[65, 65, 65, 65, 65], [65, 65, 65, 65, 65]], dtype=uint8) # Set values in array to something new. In [75]: q[1] = ord('B') In [76]: q memmap([[65, 65, 65, 65, 65], [66, 66, 66, 66, 66]], dtype=uint8) # Even after calling flush(), the underlying file is  not  updated. In [77]: q.flush() In [78]: !cat new_file.dat AAAAAAAAAA
Using Offsets # Create a memory mapped array with 10 elements. In [1]: q=memmap('new_file.dat',mode='w+', dtype=uint8, shape=(10,)) In [2]: q[:] = arange(0,100,10) memmap([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90], dtype=uint8) # Now, create a new memory mapped array (read only) with an offset into # the previously created file. In [3]: q=memmap('new_file.dat',mode='r', dtype=uint8, shape=6, offset=4) In [4]: q memmap([40, 50, 60, 70, 80, 90], dtype=uint8) # The number of bytes required by the array must be equal or less than # the number of bytes available in the file. In [3]: q=memmap('new_file.dat',mode='r', dtype=uint8, shape= 7 , offset=4) ValueError: mmap length is greater than file size new_file.dat new_file.dat
Working with file headers 64 bit floating point data
 # Create a dtype to represent the header. header_dtype = dtype([('rows', int32), ('cols', int32)]) # Create a memory mapped array using this dtype.  Note the shape is empty. header = memmap(file_name, mode='r', dtype=header_dtype, shape=()) # Read the row and column sizes from using this structured array. rows = header['rows'] cols = header['cols'] # Create a memory map to the data segment, using rows, cols for shape # information and the header size to determine the correct offset.   data = memmap(file_name, mode='r+', dtype=float64,  shape=(rows, cols), offset=header_dtype.itemsize) rows (int32) data header File Format: cols (int32)
Accessing Legacy Files header harr data darr dtype objects NumPy arrays binary file format = harr['format'] time = harr['time'] Explore in Python as NumPy Arrays a = darr['image'][:30,:40]
Strategy for creating new files!
Memmap Timings (3D arrays) All times in milliseconds (ms). Linux: Ubuntu 4.1, Dell Precision 690, Dual Quad Core Zeon X5355 2.6 GHz, 8 GB Memory OS X: OS X 10.5, MacBook Pro Laptop, 2.6 GHz Core Duo, 4 GB Memory 27 ms 3505 ms  11 ms 2103 ms read 7.4 ms 4.4 ms 4.6 ms 2.8 ms y slice 8.3 ms 1.8 ms 4.8 ms 1.8 ms x slice 0.02 ms 9.2 ms In  Memory Linux downsample 4x4 z slice Operations (500x500x1000) 198.7 ms 0.02 ms 125 ms 18.7 ms 10 ms 13.8 ms Memory Mapped In  Memory Memory Mapped OS X
Parallel FFT On Memory Mapped File 500 MB   memory  mapped data file split &  assign  rows Run parallel code on  each processor
Parallel FFT On Memory Mapped File 1.0 11.75 1 3.5 3.36 4 1.9 6.06 2 2.50 Time (seconds) 8 Processors 4.7 Speed Up
 
Introduction ,[object Object],[object Object],[object Object]
EPD & EPD Webinars: http://www. enthought . com/products/epd . php Enthought Training: http://www. enthought .com/training/

Weitere Àhnliche Inhalte

Was ist angesagt?

Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...Piotr Przymus
 
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...Piotr Przymus
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administrationvceder
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlowBayu Aldi Yansyah
 
What’s eating python performance
What’s eating python performanceWhat’s eating python performance
What’s eating python performancePiotr Przymus
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk PemulaOon Arfiandwi
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAMaulik Borsaniya
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekingeProf. Wim Van Criekinge
 
Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009A Jorge Garcia
 
2016 02 23_biological_databases_part2
2016 02 23_biological_databases_part22016 02 23_biological_databases_part2
2016 02 23_biological_databases_part2Prof. Wim Van Criekinge
 
Python scripting kick off
Python scripting kick offPython scripting kick off
Python scripting kick offAndrea Gangemi
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Pypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequelPypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequelMark Rees
 
Python Tricks That You Can't Live Without
Python Tricks That You Can't Live WithoutPython Tricks That You Can't Live Without
Python Tricks That You Can't Live WithoutAudrey Roy
 
Random And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python CgiRandom And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python CgiAkramWaseem
 

Was ist angesagt? (20)

Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
Everything You Always Wanted to Know About Memory in Python - But Were Afraid...
 
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administration
 
Hom Class
Hom ClassHom Class
Hom Class
 
Hom Class
Hom ClassHom Class
Hom Class
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
 
What’s eating python performance
What’s eating python performanceWhat’s eating python performance
What’s eating python performance
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
 
python.ppt
python.pptpython.ppt
python.ppt
 
Virtual Machine Constructions for Dummies
Virtual Machine Constructions for DummiesVirtual Machine Constructions for Dummies
Virtual Machine Constructions for Dummies
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge
 
Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009
 
2016 02 23_biological_databases_part2
2016 02 23_biological_databases_part22016 02 23_biological_databases_part2
2016 02 23_biological_databases_part2
 
Python scripting kick off
Python scripting kick offPython scripting kick off
Python scripting kick off
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Pypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequelPypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequel
 
Python Tricks That You Can't Live Without
Python Tricks That You Can't Live WithoutPython Tricks That You Can't Live Without
Python Tricks That You Can't Live Without
 
Random And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python CgiRandom And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python Cgi
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 

Andere mochten auch

Arrays
ArraysArrays
ArraysSb Sharma
 
A Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with PythonA Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with PythonTariq Rashid
 
Images and Vision in Python
Images and Vision in PythonImages and Vision in Python
Images and Vision in Pythonstreety
 
Enter The Matrix
Enter The MatrixEnter The Matrix
Enter The MatrixMike Anderson
 
PCAP Graphs for Cybersecurity and System Tuning
PCAP Graphs for Cybersecurity and System TuningPCAP Graphs for Cybersecurity and System Tuning
PCAP Graphs for Cybersecurity and System TuningDr. Mirko KĂ€mpf
 
Realtime Detection of DDOS attacks using Apache Spark and MLLib
Realtime Detection of DDOS attacks using Apache Spark and MLLibRealtime Detection of DDOS attacks using Apache Spark and MLLib
Realtime Detection of DDOS attacks using Apache Spark and MLLibRyan Bosshart
 
퍼ᄋᅔᄊᅄᆫ Numpy á„‰á…„á†«á„’á…§á†Œá„ƒá…ąá„‰á…ź ᄋᅔᄒᅹ허ᄀᅔ
퍼ᄋᅔᄊᅄᆫ Numpy á„‰á…„á†«á„’á…§á†Œá„ƒá…ąá„‰á…ź ᄋᅔᄒᅹ허ᄀᅔ퍼ᄋᅔᄊᅄᆫ Numpy á„‰á…„á†«á„’á…§á†Œá„ƒá…ąá„‰á…ź ᄋᅔᄒᅹ허ᄀᅔ
퍼ᄋᅔᄊᅄᆫ Numpy á„‰á…„á†«á„’á…§á†Œá„ƒá…ąá„‰á…ź ᄋᅔᄒᅹ허ᄀᅔYong Joon Moon
 
Getting started with image processing using Matlab
Getting started with image processing using MatlabGetting started with image processing using Matlab
Getting started with image processing using MatlabPantech ProLabs India Pvt Ltd
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkRahul Jain
 

Andere mochten auch (10)

Arrays
ArraysArrays
Arrays
 
2nd section
2nd section2nd section
2nd section
 
A Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with PythonA Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with Python
 
Images and Vision in Python
Images and Vision in PythonImages and Vision in Python
Images and Vision in Python
 
Enter The Matrix
Enter The MatrixEnter The Matrix
Enter The Matrix
 
PCAP Graphs for Cybersecurity and System Tuning
PCAP Graphs for Cybersecurity and System TuningPCAP Graphs for Cybersecurity and System Tuning
PCAP Graphs for Cybersecurity and System Tuning
 
Realtime Detection of DDOS attacks using Apache Spark and MLLib
Realtime Detection of DDOS attacks using Apache Spark and MLLibRealtime Detection of DDOS attacks using Apache Spark and MLLib
Realtime Detection of DDOS attacks using Apache Spark and MLLib
 
퍼ᄋᅔᄊᅄᆫ Numpy á„‰á…„á†«á„’á…§á†Œá„ƒá…ąá„‰á…ź ᄋᅔᄒᅹ허ᄀᅔ
퍼ᄋᅔᄊᅄᆫ Numpy á„‰á…„á†«á„’á…§á†Œá„ƒá…ąá„‰á…ź ᄋᅔᄒᅹ허ᄀᅔ퍼ᄋᅔᄊᅄᆫ Numpy á„‰á…„á†«á„’á…§á†Œá„ƒá…ąá„‰á…ź ᄋᅔᄒᅹ허ᄀᅔ
퍼ᄋᅔᄊᅄᆫ Numpy á„‰á…„á†«á„’á…§á†Œá„ƒá…ąá„‰á…ź ᄋᅔᄒᅹ허ᄀᅔ
 
Getting started with image processing using Matlab
Getting started with image processing using MatlabGetting started with image processing using Matlab
Getting started with image processing using Matlab
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache Spark
 

Ähnlich wie Scientific Computing with Python Webinar --- May 22, 2009

The bones of a nice Python script
The bones of a nice Python scriptThe bones of a nice Python script
The bones of a nice Python scriptsaniac
 
Good practices for PrestaShop code security and optimization
Good practices for PrestaShop code security and optimizationGood practices for PrestaShop code security and optimization
Good practices for PrestaShop code security and optimizationPrestaShop
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate WorksGoro Fuji
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce AlgorithmsAmund Tveit
 
PyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdfPyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdfAlessandro Molina
 
A Rusty introduction to Apache Arrow and how it applies to a time series dat...
A Rusty introduction to Apache Arrow and how it applies to a  time series dat...A Rusty introduction to Apache Arrow and how it applies to a  time series dat...
A Rusty introduction to Apache Arrow and how it applies to a time series dat...Andrew Lamb
 
Easy R
Easy REasy R
Easy RAjay Ohri
 
C to perl binding
C to perl bindingC to perl binding
C to perl bindingShmuel Fomberg
 
Async and Parallel F#
Async and Parallel F#Async and Parallel F#
Async and Parallel F#mattpodwysocki
 
Async and Parallel F#
Async and Parallel F#Async and Parallel F#
Async and Parallel F#mattpodwysocki
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlProf. Wim Van Criekinge
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questionsSrikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
Rendering OpenStreetMap Data using Mapnik
Rendering OpenStreetMap Data using MapnikRendering OpenStreetMap Data using Mapnik
Rendering OpenStreetMap Data using MapnikGraham Jones
 
e_lumley.pdf
e_lumley.pdfe_lumley.pdf
e_lumley.pdfbetsegaw123
 
Characterset
CharactersetCharacterset
CharactersetHari K T
 

Ähnlich wie Scientific Computing with Python Webinar --- May 22, 2009 (20)

The bones of a nice Python script
The bones of a nice Python scriptThe bones of a nice Python script
The bones of a nice Python script
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
Good practices for PrestaShop code security and optimization
Good practices for PrestaShop code security and optimizationGood practices for PrestaShop code security and optimization
Good practices for PrestaShop code security and optimization
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate Works
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce Algorithms
 
PyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdfPyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdf
 
A Rusty introduction to Apache Arrow and how it applies to a time series dat...
A Rusty introduction to Apache Arrow and how it applies to a  time series dat...A Rusty introduction to Apache Arrow and how it applies to a  time series dat...
A Rusty introduction to Apache Arrow and how it applies to a time series dat...
 
Easy R
Easy REasy R
Easy R
 
Python 3000
Python 3000Python 3000
Python 3000
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
Async and Parallel F#
Async and Parallel F#Async and Parallel F#
Async and Parallel F#
 
Async and Parallel F#
Async and Parallel F#Async and Parallel F#
Async and Parallel F#
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperl
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Modern C++
Modern C++Modern C++
Modern C++
 
Rendering OpenStreetMap Data using Mapnik
Rendering OpenStreetMap Data using MapnikRendering OpenStreetMap Data using Mapnik
Rendering OpenStreetMap Data using Mapnik
 
e_lumley.pdf
e_lumley.pdfe_lumley.pdf
e_lumley.pdf
 
Characterset
CharactersetCharacterset
Characterset
 

Mehr von Enthought, Inc.

Numpy Talk at SIAM
Numpy Talk at SIAMNumpy Talk at SIAM
Numpy Talk at SIAMEnthought, Inc.
 
Talk at NYC Python Meetup Group
Talk at NYC Python Meetup GroupTalk at NYC Python Meetup Group
Talk at NYC Python Meetup GroupEnthought, Inc.
 
Scientific Applications with Python
Scientific Applications with PythonScientific Applications with Python
Scientific Applications with PythonEnthought, Inc.
 
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviScientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviEnthought, Inc.
 
Chaco Step-by-Step
Chaco Step-by-StepChaco Step-by-Step
Chaco Step-by-StepEnthought, Inc.
 
NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy StatisticsEnthought, Inc.
 
February EPD Webinar: How do I...use PiCloud for cloud computing?
February EPD Webinar: How do I...use PiCloud for cloud computing?February EPD Webinar: How do I...use PiCloud for cloud computing?
February EPD Webinar: How do I...use PiCloud for cloud computing?Enthought, Inc.
 
Parallel Processing with IPython
Parallel Processing with IPythonParallel Processing with IPython
Parallel Processing with IPythonEnthought, Inc.
 
Scientific Computing with Python Webinar: Traits
Scientific Computing with Python Webinar: TraitsScientific Computing with Python Webinar: Traits
Scientific Computing with Python Webinar: TraitsEnthought, Inc.
 
Scientific Computing with Python Webinar 9/18/2009:Curve Fitting
Scientific Computing with Python Webinar 9/18/2009:Curve FittingScientific Computing with Python Webinar 9/18/2009:Curve Fitting
Scientific Computing with Python Webinar 9/18/2009:Curve FittingEnthought, Inc.
 
Scientific Computing with Python Webinar --- August 28, 2009
Scientific Computing with Python Webinar --- August 28, 2009Scientific Computing with Python Webinar --- August 28, 2009
Scientific Computing with Python Webinar --- August 28, 2009Enthought, Inc.
 
Scientific Computing with Python Webinar --- June 19, 2009
Scientific Computing with Python Webinar --- June 19, 2009Scientific Computing with Python Webinar --- June 19, 2009
Scientific Computing with Python Webinar --- June 19, 2009Enthought, Inc.
 

Mehr von Enthought, Inc. (14)

Numpy Talk at SIAM
Numpy Talk at SIAMNumpy Talk at SIAM
Numpy Talk at SIAM
 
Talk at NYC Python Meetup Group
Talk at NYC Python Meetup GroupTalk at NYC Python Meetup Group
Talk at NYC Python Meetup Group
 
Scientific Applications with Python
Scientific Applications with PythonScientific Applications with Python
Scientific Applications with Python
 
SciPy 2010 Review
SciPy 2010 ReviewSciPy 2010 Review
SciPy 2010 Review
 
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviScientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
 
Chaco Step-by-Step
Chaco Step-by-StepChaco Step-by-Step
Chaco Step-by-Step
 
NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy Statistics
 
February EPD Webinar: How do I...use PiCloud for cloud computing?
February EPD Webinar: How do I...use PiCloud for cloud computing?February EPD Webinar: How do I...use PiCloud for cloud computing?
February EPD Webinar: How do I...use PiCloud for cloud computing?
 
SciPy India 2009
SciPy India 2009SciPy India 2009
SciPy India 2009
 
Parallel Processing with IPython
Parallel Processing with IPythonParallel Processing with IPython
Parallel Processing with IPython
 
Scientific Computing with Python Webinar: Traits
Scientific Computing with Python Webinar: TraitsScientific Computing with Python Webinar: Traits
Scientific Computing with Python Webinar: Traits
 
Scientific Computing with Python Webinar 9/18/2009:Curve Fitting
Scientific Computing with Python Webinar 9/18/2009:Curve FittingScientific Computing with Python Webinar 9/18/2009:Curve Fitting
Scientific Computing with Python Webinar 9/18/2009:Curve Fitting
 
Scientific Computing with Python Webinar --- August 28, 2009
Scientific Computing with Python Webinar --- August 28, 2009Scientific Computing with Python Webinar --- August 28, 2009
Scientific Computing with Python Webinar --- August 28, 2009
 
Scientific Computing with Python Webinar --- June 19, 2009
Scientific Computing with Python Webinar --- June 19, 2009Scientific Computing with Python Webinar --- June 19, 2009
Scientific Computing with Python Webinar --- June 19, 2009
 

KĂŒrzlich hochgeladen

Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 

KĂŒrzlich hochgeladen (20)

Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Scientific Computing with Python Webinar --- May 22, 2009

  • 2. A word from our sponsor

  • 3.
  • 4. Enthought Python Distribution (EPD) Explanations, demonstrations, and tips For subscribers to Enthought Python Distribution (EPD) and their guests. Presenters and Panelists will include Enthought experts and other leading community members.
  • 5. Enthought Training Courses Python Basics, NumPy, SciPy, Matplotlib, Traits, TraitsUI, Chaco

  • 6. Upcoming Training Classes June 15 - 19, 2009 Introduction to Scientific Computing with Python Austin, Texas July, 2009 TBA August, 2009 TBA September 21 to 25, 2009 Introduction to Scientific Computing with Python Austin, Texas http://www.enthought.com/training/
  • 7. Enthought Consulting Process Built with Python by a team of scientists, EPD provides a versatile and coherent platform for analysis and visualization .
  • 8. Software Application Layers Python NumPy (Array Mathematics) SciPy (Scientific Algorithms) 3 rd Party Libraries wxPython VTK, etc. ETS (App construction) Traits, Chaco, Mayavi, Envisage, etc. Domain Specific GUI Applications Semiconductor, Fluid Dynamics, Seismic Modeling, Financial, etc.
  • 11.
  • 12. Multiple Plug-ins. One Application
  • 13.  
  • 14. Database Access Compliance Tools Equipment Interface Scientific Algorithms UI Elements Testing Framework Scripting Interface Chaco Plotting Data Display Rich Client App (Geophysics, Finance, Etc)
  • 15. NumPy
  • 17. “Structured” Arrays name char[10] age int weight double Elements of an array can be any fixed-size data structure! EXAMPLE >>> from numpy import dtype, empty # structured data format >>> fmt = dtype([('name', 'S10'), ('age', int), ('weight', float) ]) >>> a = empty((3,4), dtype=fmt) >>> a.itemsize 22 >>> a['name'] = [['Brad', ,'Jill']] >>> a['age'] = [[33, ,54]] >>> a['weight'] = [[135, ,145]] >>> print a [[('Brad', 33, 135.0) ('Jill', 54, 145.0)]] 27 32 61 29 145.0 88.0 135.0 188.0 54 18 33 19 Jill Jennifer Susan Ron 187.0 137.0 202.0 154.0 Amy Brian George Henry 140.0 225.0 105.0 135.0 54 47 25 33 Fred John Jane Brad
  • 19. Nested Datatype dt = dtype([('time', np.uint64), ('size', np.uint32), ('position', [('az', np.float32), ('el', np.float32), ('region_type', np.uint8), ('region_ID', np.uint16)]), ('gain', np.uint8), ('samples', (np.int16,2048))]) data = np.fromfile(f, dtype=dt) If you only wanted to access a part of the file use a memory map
  • 20. Virtual Memory http://en.wikipedia.org/wiki/Virtual_memory Memory mapped files are like intentional disk-based virutal memory
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. memmap -- write through behavior # Create a memory mapped &quot;write through&quot; file, overwriting it if it exists. In [66]: q=memmap('new_file.dat',mode='w+',shape=(2,5)) In [67]: q memmap([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], dtype=uint8) # Print out the contents of the underlying file. Note: It # doesn't print because 0 isn't a printable ascii character. In [68]: !cat new_file.dat # Now write the ascii value for 'A' (65) into our array. In [69]: q[:] = ord('A') In [70]: q memmap([[65, 65, 65, 65, 65], [65, 65, 65, 65, 65]], dtype=uint8) # Ensure the OS has written the data to the file, and examine # the underlying file. It is full of 'A's as we hope. In [71]: q.flush() In [72]: !cat new_file.dat AAAAAAAAAA
  • 26. memmap -- copy on write behavior # Create a copy-on-write memory map where the underlying file is never # modified. The file must already exist. # This is a memory efficient way of working with data on disk as arrays but # ensuring you never modify it. In [73]: q=memmap('new_file.dat',mode='c',shape=(2,5)) In [74]: q memmap([[65, 65, 65, 65, 65], [65, 65, 65, 65, 65]], dtype=uint8) # Set values in array to something new. In [75]: q[1] = ord('B') In [76]: q memmap([[65, 65, 65, 65, 65], [66, 66, 66, 66, 66]], dtype=uint8) # Even after calling flush(), the underlying file is not updated. In [77]: q.flush() In [78]: !cat new_file.dat AAAAAAAAAA
  • 27. Using Offsets # Create a memory mapped array with 10 elements. In [1]: q=memmap('new_file.dat',mode='w+', dtype=uint8, shape=(10,)) In [2]: q[:] = arange(0,100,10) memmap([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90], dtype=uint8) # Now, create a new memory mapped array (read only) with an offset into # the previously created file. In [3]: q=memmap('new_file.dat',mode='r', dtype=uint8, shape=6, offset=4) In [4]: q memmap([40, 50, 60, 70, 80, 90], dtype=uint8) # The number of bytes required by the array must be equal or less than # the number of bytes available in the file. In [3]: q=memmap('new_file.dat',mode='r', dtype=uint8, shape= 7 , offset=4) ValueError: mmap length is greater than file size new_file.dat new_file.dat
  • 28. Working with file headers 64 bit floating point data
 # Create a dtype to represent the header. header_dtype = dtype([('rows', int32), ('cols', int32)]) # Create a memory mapped array using this dtype. Note the shape is empty. header = memmap(file_name, mode='r', dtype=header_dtype, shape=()) # Read the row and column sizes from using this structured array. rows = header['rows'] cols = header['cols'] # Create a memory map to the data segment, using rows, cols for shape # information and the header size to determine the correct offset. data = memmap(file_name, mode='r+', dtype=float64, shape=(rows, cols), offset=header_dtype.itemsize) rows (int32) data header File Format: cols (int32)
  • 29. Accessing Legacy Files header harr data darr dtype objects NumPy arrays binary file format = harr['format'] time = harr['time'] Explore in Python as NumPy Arrays a = darr['image'][:30,:40]
  • 30. Strategy for creating new files!
  • 31. Memmap Timings (3D arrays) All times in milliseconds (ms). Linux: Ubuntu 4.1, Dell Precision 690, Dual Quad Core Zeon X5355 2.6 GHz, 8 GB Memory OS X: OS X 10.5, MacBook Pro Laptop, 2.6 GHz Core Duo, 4 GB Memory 27 ms 3505 ms 11 ms 2103 ms read 7.4 ms 4.4 ms 4.6 ms 2.8 ms y slice 8.3 ms 1.8 ms 4.8 ms 1.8 ms x slice 0.02 ms 9.2 ms In Memory Linux downsample 4x4 z slice Operations (500x500x1000) 198.7 ms 0.02 ms 125 ms 18.7 ms 10 ms 13.8 ms Memory Mapped In Memory Memory Mapped OS X
  • 32. Parallel FFT On Memory Mapped File 500 MB memory mapped data file split & assign rows Run parallel code on each processor
  • 33. Parallel FFT On Memory Mapped File 1.0 11.75 1 3.5 3.36 4 1.9 6.06 2 2.50 Time (seconds) 8 Processors 4.7 Speed Up
  • 34.  
  • 35.
  • 36. EPD & EPD Webinars: http://www. enthought . com/products/epd . php Enthought Training: http://www. enthought .com/training/