SlideShare a Scribd company logo
1 of 25
Download to read offline
Using NumPy
efficiently
David Cournapeau

@cournape github.com/cournape
Hello
• I am David Cournapeau (ダビ
ド): @cournape (twitter/github)

• NumPy/SciPy user since 2005

• Former core contributor to
NumPy, SciPy

• Started the learn project, which
would later become scikit learn

• Currently leading ML
Engineering team at Cogent
Labs
PyData stack today
Why would you care about
NumPy ?
• Used a fundamental piece in many higher level Machine Learning
libraries (scikit learn/image, pandas, Tensorflow/Chainer/PyTorch)

• Required to understand the source code of those libraries

• Historically: key enabler of python for ML and Data Science

• NumPy is a library for array computing

• Long history in computing (APL, J, K, Matlab, etc…): see e.g.
http://jsoftware.com/

• Both about efficiency and expressivity
A bit of history
• Early work for array computing in Python (matrix-sig mailing
list):

• 1995: Jim Fulton, Jim Hugunin. Became Numeric

• 1995-2000ies: Paul Dubois, Konrad Hinsen, David Ascher,
Travis Oliphant and other contributed later

• 2001: Numarray: Perry Greenfield, Rick White and Todd
Miller

• 2005: “grand unification” into NumPy, led by Travis
Oliphant
Array Computing for speed
• You want to compute some math operations:
• In NumPy:
Why the difference ?
• Why (c)python is slow for computation: boxing
From Python Data Science Handbook by Jake Vanderplas
Why the difference ?
• Why (c)python is slow for
computation: genericity

• E.g. lists can contains arbitrary
python values

• You need to jump pointers to
access values

• Note: accessing an arbitrary
value in RAM costs ~ 100
cycles (as much as computing
the exponential of a double in
C !)
From Python Data Science Handbook by Jake Vanderplas
Array computing for
expressivity
• One simple ReLU layer in neural network for 1d vector x:
logits = W @ x + b
output = softmax(logits)
print(logits.shape)
• Maps more directly to many scientific domains
Structure of NumPy arrays
• A NumPy array is essentially:

• A single bloc of memory

• A dtype to describe how to interpret single values in the
memory bloc

• Metadata such as shape, strides, etc.

• NumPy arrays memory cost same as C + constant
Structure of NumPy arrays
• Data is like a C array

• Dtype is a python object with
information about values in
the array (size, endianness,
etc.)

• dimensions, strides and dtype
are used for multidimensional
indexing
Example
• Notebook example for array creation, metadata and
simple slices
Broadcasting 1/4
• Linear Algebra defines most basic NumPy operations

• We do not always want to be as strict as mathematics:

• We want to add scalar to arrays without having to
create arrays with the duplicated scalar

• We sometimes do not care about row vs column vector

• We sometimes want to save memory and avoid
temporaries
Broadcasting 2/4
• Broadcasting: rules to work with arrays (and scalars) with
non conforming shapes 

• NumPy provides powerful broadcasting capabilities
import numpy as np
# np.newaxis creates a new dimension, but array has the same size
x = np.arange(5)[:, np.newaxis]
y = np.arange(5)
print(x + y)
Broadcasting 3/4
• Broadcasting rules:

• If arrays have different number
of dimensions, insert new axes
on the left until arrays have
same number of dimensions

• For each axis i, if arrays
dimension[i] do not match,
“stretch” the arrays where
dimension[i] = 1 to match
other array(s) 

• (if no match and dimension[i] !
= 1 -> error) From Python Data Science Handbook by Jake Vanderplas
Broadcasting 4/4
• A few notes:

• Broadcasting is done “logically”, and the temporary arrays
are not created in memory

• Integrated in the ufunc and multi-dimensional indexing
infrastructure in NumPy code (see later)

• Indices are broadcasted as well in fancy indexing (see
later)

• You can use np.broadcast_arrays to explicitly build arrays
as if they were broadcasted
Indexing: views
• One can use slices any time
one needs to extract “regular”
subarrays

• If arrays are solely indexed
through slices, the returned
array is a view (no data
copied)
import numpy as np
x = np.arange(6).reshape(2, 3)
print(x)
print(x[:, ::2])
print(x[::2, ::2])
Examples
Indexing: fancy indexing
• As soon as you index an array with an array, you are using
fancy indexing

• Fancy indexing always returns a copy (why ?)

• 2 main cases of fancy indexing:

• Use an array of boolean (aka mask)

• Use an array of integers

• Fancy indexing can get too fancy…
Fancy indexing with masks
• Indexing with array of booleans

• Appears naturally with comparison
Fancy indexing with integer
arrays
• Indexing with array of integers

• Appears naturally to select specific values from their
indices
Does not sound that
fancy ?
See Jaime Fernández - The Future of NumPy Indexing presentation
Sebastian Berge: new fancy indexing NEP
How to go further
• From Python to NumPy by Nicolas Rougier: http://
www.labri.fr/perso/nrougier/from-python-to-numpy

• 100 NumPy exercises by Nicolas Rougier: https://
github.com/rougier/numpy-100/blob/master/
100%20Numpy%20exercises.md

• Guide to NumPy: http://web.mit.edu/dvp/Public/
numpybook.pdf

• “New” ND index by Mark Wiebe, with notes about speeding
up indexing, etc.: https://github.com/numpy/numpy/blob/
master/doc/neps/nep-0010-new-iterator-ufunc.rst
Thank you

More Related Content

What's hot

Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPyDevashish Kumar
 
Tensorflow presentation
Tensorflow presentationTensorflow presentation
Tensorflow presentationAhmed rebai
 
Python array API standardization - current state and benefits
Python array API standardization - current state and benefitsPython array API standardization - current state and benefits
Python array API standardization - current state and benefitsRalf Gommers
 
Python for Computer Vision - Revision
Python for Computer Vision - RevisionPython for Computer Vision - Revision
Python for Computer Vision - RevisionAhmed Gad
 
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...Big Data Spain
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internalHyunghun Cho
 
Numpy and scipy
Numpy and scipyNumpy and scipy
Numpy and scipytarun_483
 
Introduction To Using TensorFlow & Deep Learning
Introduction To Using TensorFlow & Deep LearningIntroduction To Using TensorFlow & Deep Learning
Introduction To Using TensorFlow & Deep Learningali alemi
 
1.5.ensemble learning with apache spark m llib 1.5
1.5.ensemble learning with apache spark m llib 1.51.5.ensemble learning with apache spark m llib 1.5
1.5.ensemble learning with apache spark m llib 1.5leorick lin
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1Jatin Miglani
 
Multithreading to Construct Neural Networks
Multithreading to Construct Neural NetworksMultithreading to Construct Neural Networks
Multithreading to Construct Neural NetworksAltoros
 
Introduction to TensorFlow
Introduction to TensorFlowIntroduction to TensorFlow
Introduction to TensorFlowMatthias Feys
 
Queues in data structures
Queues in data structuresQueues in data structures
Queues in data structuresEdison Tusifu
 

What's hot (20)

Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
 
NumPy
NumPyNumPy
NumPy
 
Tensorflow presentation
Tensorflow presentationTensorflow presentation
Tensorflow presentation
 
Python array API standardization - current state and benefits
Python array API standardization - current state and benefitsPython array API standardization - current state and benefits
Python array API standardization - current state and benefits
 
Python for Computer Vision - Revision
Python for Computer Vision - RevisionPython for Computer Vision - Revision
Python for Computer Vision - Revision
 
1. C Basics for Data Structures Bridge Course
1. C Basics for Data Structures   Bridge Course1. C Basics for Data Structures   Bridge Course
1. C Basics for Data Structures Bridge Course
 
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internal
 
Python for lab_folk
Python for lab_folkPython for lab_folk
Python for lab_folk
 
Essential NumPy
Essential NumPyEssential NumPy
Essential NumPy
 
Numpy
NumpyNumpy
Numpy
 
Lec3
Lec3Lec3
Lec3
 
Numpy and scipy
Numpy and scipyNumpy and scipy
Numpy and scipy
 
Introduction To Using TensorFlow & Deep Learning
Introduction To Using TensorFlow & Deep LearningIntroduction To Using TensorFlow & Deep Learning
Introduction To Using TensorFlow & Deep Learning
 
1.5.ensemble learning with apache spark m llib 1.5
1.5.ensemble learning with apache spark m llib 1.51.5.ensemble learning with apache spark m llib 1.5
1.5.ensemble learning with apache spark m llib 1.5
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1
 
Multithreading to Construct Neural Networks
Multithreading to Construct Neural NetworksMultithreading to Construct Neural Networks
Multithreading to Construct Neural Networks
 
Tensor flow
Tensor flowTensor flow
Tensor flow
 
Introduction to TensorFlow
Introduction to TensorFlowIntroduction to TensorFlow
Introduction to TensorFlow
 
Queues in data structures
Queues in data structuresQueues in data structures
Queues in data structures
 

Similar to Kaggle tokyo 2018

Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxQ-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxkalai75
 
Introduction to numpy.pptx
Introduction to numpy.pptxIntroduction to numpy.pptx
Introduction to numpy.pptxssuser0e701a
 
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
 
3 python packages
3 python packages3 python packages
3 python packagesFEG
 
ANN-Lecture2-Python Startup.pptx
ANN-Lecture2-Python Startup.pptxANN-Lecture2-Python Startup.pptx
ANN-Lecture2-Python Startup.pptxShahzadAhmadJoiya3
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to pythonActiveState
 
It's the memory, stupid! CodeJam 2014
It's the memory, stupid!  CodeJam 2014It's the memory, stupid!  CodeJam 2014
It's the memory, stupid! CodeJam 2014Francesc Alted
 
Array computing and the evolution of SciPy, NumPy, and PyData
Array computing and the evolution of SciPy, NumPy, and PyDataArray computing and the evolution of SciPy, NumPy, and PyData
Array computing and the evolution of SciPy, NumPy, and PyDataTravis Oliphant
 
The Joy of SciPy
The Joy of SciPyThe Joy of SciPy
The Joy of SciPykammeyer
 
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptxPython-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptxanushya2915
 
OpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon ValleyOpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon ValleyGanesan Narayanasamy
 
Introduction to Convolutional Neural Networks
Introduction to Convolutional Neural NetworksIntroduction to Convolutional Neural Networks
Introduction to Convolutional Neural NetworksHannes Hapke
 

Similar to Kaggle tokyo 2018 (20)

Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxQ-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
 
Introduction to numpy.pptx
Introduction to numpy.pptxIntroduction to numpy.pptx
Introduction to numpy.pptx
 
Session 2
Session 2Session 2
Session 2
 
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"
 
Scientific Python
Scientific PythonScientific Python
Scientific Python
 
3 python packages
3 python packages3 python packages
3 python packages
 
ANN-Lecture2-Python Startup.pptx
ANN-Lecture2-Python Startup.pptxANN-Lecture2-Python Startup.pptx
ANN-Lecture2-Python Startup.pptx
 
Python for ML.pptx
Python for ML.pptxPython for ML.pptx
Python for ML.pptx
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
 
It's the memory, stupid! CodeJam 2014
It's the memory, stupid!  CodeJam 2014It's the memory, stupid!  CodeJam 2014
It's the memory, stupid! CodeJam 2014
 
Array computing and the evolution of SciPy, NumPy, and PyData
Array computing and the evolution of SciPy, NumPy, and PyDataArray computing and the evolution of SciPy, NumPy, and PyData
Array computing and the evolution of SciPy, NumPy, and PyData
 
PyData Boston 2013
PyData Boston 2013PyData Boston 2013
PyData Boston 2013
 
Pa2 session 1
Pa2 session 1Pa2 session 1
Pa2 session 1
 
The Joy of SciPy
The Joy of SciPyThe Joy of SciPy
The Joy of SciPy
 
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptxPython-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
 
OpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon ValleyOpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon Valley
 
Introduction to Convolutional Neural Networks
Introduction to Convolutional Neural NetworksIntroduction to Convolutional Neural Networks
Introduction to Convolutional Neural Networks
 
PyCon Estonia 2019
PyCon Estonia 2019PyCon Estonia 2019
PyCon Estonia 2019
 

Recently uploaded

Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 

Recently uploaded (20)

Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 

Kaggle tokyo 2018

  • 2. Hello • I am David Cournapeau (ダビ ド): @cournape (twitter/github) • NumPy/SciPy user since 2005 • Former core contributor to NumPy, SciPy • Started the learn project, which would later become scikit learn • Currently leading ML Engineering team at Cogent Labs
  • 4. Why would you care about NumPy ? • Used a fundamental piece in many higher level Machine Learning libraries (scikit learn/image, pandas, Tensorflow/Chainer/PyTorch) • Required to understand the source code of those libraries • Historically: key enabler of python for ML and Data Science • NumPy is a library for array computing • Long history in computing (APL, J, K, Matlab, etc…): see e.g. http://jsoftware.com/ • Both about efficiency and expressivity
  • 5. A bit of history • Early work for array computing in Python (matrix-sig mailing list): • 1995: Jim Fulton, Jim Hugunin. Became Numeric • 1995-2000ies: Paul Dubois, Konrad Hinsen, David Ascher, Travis Oliphant and other contributed later • 2001: Numarray: Perry Greenfield, Rick White and Todd Miller • 2005: “grand unification” into NumPy, led by Travis Oliphant
  • 6. Array Computing for speed • You want to compute some math operations: • In NumPy:
  • 7. Why the difference ? • Why (c)python is slow for computation: boxing From Python Data Science Handbook by Jake Vanderplas
  • 8. Why the difference ? • Why (c)python is slow for computation: genericity • E.g. lists can contains arbitrary python values • You need to jump pointers to access values • Note: accessing an arbitrary value in RAM costs ~ 100 cycles (as much as computing the exponential of a double in C !) From Python Data Science Handbook by Jake Vanderplas
  • 9. Array computing for expressivity • One simple ReLU layer in neural network for 1d vector x: logits = W @ x + b output = softmax(logits) print(logits.shape) • Maps more directly to many scientific domains
  • 10. Structure of NumPy arrays • A NumPy array is essentially: • A single bloc of memory • A dtype to describe how to interpret single values in the memory bloc • Metadata such as shape, strides, etc. • NumPy arrays memory cost same as C + constant
  • 11. Structure of NumPy arrays • Data is like a C array • Dtype is a python object with information about values in the array (size, endianness, etc.) • dimensions, strides and dtype are used for multidimensional indexing
  • 12. Example • Notebook example for array creation, metadata and simple slices
  • 13. Broadcasting 1/4 • Linear Algebra defines most basic NumPy operations • We do not always want to be as strict as mathematics: • We want to add scalar to arrays without having to create arrays with the duplicated scalar • We sometimes do not care about row vs column vector • We sometimes want to save memory and avoid temporaries
  • 14. Broadcasting 2/4 • Broadcasting: rules to work with arrays (and scalars) with non conforming shapes • NumPy provides powerful broadcasting capabilities import numpy as np # np.newaxis creates a new dimension, but array has the same size x = np.arange(5)[:, np.newaxis] y = np.arange(5) print(x + y)
  • 15. Broadcasting 3/4 • Broadcasting rules: • If arrays have different number of dimensions, insert new axes on the left until arrays have same number of dimensions • For each axis i, if arrays dimension[i] do not match, “stretch” the arrays where dimension[i] = 1 to match other array(s) • (if no match and dimension[i] ! = 1 -> error) From Python Data Science Handbook by Jake Vanderplas
  • 16. Broadcasting 4/4 • A few notes: • Broadcasting is done “logically”, and the temporary arrays are not created in memory • Integrated in the ufunc and multi-dimensional indexing infrastructure in NumPy code (see later) • Indices are broadcasted as well in fancy indexing (see later) • You can use np.broadcast_arrays to explicitly build arrays as if they were broadcasted
  • 17. Indexing: views • One can use slices any time one needs to extract “regular” subarrays • If arrays are solely indexed through slices, the returned array is a view (no data copied) import numpy as np x = np.arange(6).reshape(2, 3) print(x) print(x[:, ::2]) print(x[::2, ::2])
  • 19. Indexing: fancy indexing • As soon as you index an array with an array, you are using fancy indexing • Fancy indexing always returns a copy (why ?) • 2 main cases of fancy indexing: • Use an array of boolean (aka mask) • Use an array of integers • Fancy indexing can get too fancy…
  • 20. Fancy indexing with masks • Indexing with array of booleans • Appears naturally with comparison
  • 21. Fancy indexing with integer arrays • Indexing with array of integers • Appears naturally to select specific values from their indices
  • 22. Does not sound that fancy ?
  • 23. See Jaime Fernández - The Future of NumPy Indexing presentation Sebastian Berge: new fancy indexing NEP
  • 24. How to go further • From Python to NumPy by Nicolas Rougier: http:// www.labri.fr/perso/nrougier/from-python-to-numpy • 100 NumPy exercises by Nicolas Rougier: https:// github.com/rougier/numpy-100/blob/master/ 100%20Numpy%20exercises.md • Guide to NumPy: http://web.mit.edu/dvp/Public/ numpybook.pdf • “New” ND index by Mark Wiebe, with notes about speeding up indexing, etc.: https://github.com/numpy/numpy/blob/ master/doc/neps/nep-0010-new-iterator-ufunc.rst