CSC326 Lecture 5 - 6 - CSC326 Array Programming Paradigm i...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC326 Array Programming Paradigm i CSC326 Array Programming Paradigm
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSC326 Array Programming Paradigm ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME 1.0 2011-09 JZ
Background image of page 2
CSC326 Array Programming Paradigm iii Contents 1 Agenda 1 2 Array Programming Language 1 3 NumPy Package 2 4 Creating Array 3 5 Changing Shape 4 6 Indexing and Slicing 5 7 Enumeration 6 8 Elementwise Operations 6 9 Universal Functions 7 10 More indexing 8 11 Broadcasting 9 12 Fractal Example 9 13 Sum and Partial Sum 12 14 Reduction 13 15 Reduction/Scan In Python 14 16 Parallel Reduction and Scan 15 17 Inner Product 15 18 Directed Graph 16 19 Recap 16
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSC326 Array Programming Paradigm 1 / 16 1 Agenda • Array Programming Paradigm • NumPy • Array as collection • Elementwise operations • Reduction 2 Array Programming Language • Native sequences are nice But very general: element can be anything Slow for large scale data and numerical computation • Array Programming Paradigm Everything is an array No loops! (we already saw list comprehension) • APL (A Programming Language) Kenneth E. Iverson: Candian Computer Scientist Turing Speech: "Notations as a Tool of Thoughts" (one of the most inspiring talks in CS) Influenced spreadsheets, functional programming, and computer math packages • Vector machine Vector Machine Each register is an array Instructions operate on arrays Seymour Cray: Father of Supercomputer • Question: How to Combine performance of C Expressive Power of APL Python as a language substrate • NumPy: Multidimensional arrays! Vector / Matrix Photo: Tables
Background image of page 4
CSC326 Array Programming Paradigm 2 / 16 3 NumPy Package • Retrieving source >wget url • Unpack >tar xvfz foo.tar.gz • Installation setup.py >python setup.py build >python setup.py install --user • Ready to import >python >>>import numpy as np ..... NumPy Type: ndarray • Rank Number of dimensions • Axis Each dimension • Shape tuple of integers indicating the size of the array in each dimension • accessors a.ndim: rank a.shape: shape a.size: total number of elements (prod of all elements of shape) a.itemsize: number of bytes for each elements a.dtype: data type of each element a.data: actual data (do not use directly)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSC326 Array Programming Paradigm 3 / 16 >>> from numpy import * >>> a = arange(10).reshape(2,5) >>> a array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) >>> a.shape (2, 5) >>> a.ndim 2 >>> a.dtype.name ’int32’ >>> a.itemsize 4 >>> a.size 10 4 Creating Array • array function Convert from sequences >>> import numpy as np >>> a = np.array( [2,3,4] ) >>> a array([2, 3, 4]) >>> a.dtype dtype(’int32’) >>> b = array([1.2, 3.5, 5.1]) >>> b.dtype dtype(’float64’) • Or sequences of sequences . . . >>> b = np.array( [ (1.5,2,3), (4,5,6) ] )
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/20/2012 for the course CSC 326 taught by Professor Jzhu during the Fall '11 term at University of Toronto- Toronto.

Page1 / 19

CSC326 Lecture 5 - 6 - CSC326 Array Programming Paradigm i...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online