Numerical Computing with NumPy: A Comprehensive Guide to Arrays and Vectorization, Slides of Programming Languages

python programming language for finance fields

Typology: Slides

2022/2023

Uploaded on 11/07/2023

emelia-goh
emelia-goh 🇹🇭

5 documents

1 / 51

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Numerical Computing with Numpy
1
Python interpreter has built-in data structures.
NumPy adds valuable functionality to existing structures.
This session focuses on NumPy. àProvides multidimensional array object which stores
homogeneous or heterogeneous data arrays.
It also Supports code vectorization.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33

Partial preview of the text

Download Numerical Computing with NumPy: A Comprehensive Guide to Arrays and Vectorization and more Slides Programming Languages in PDF only on Docsity!

Numerical Computing with Numpy

  • Python interpreter has built-in data structures.
  • NumPy adds valuable functionality to existing structures.
  • This session focuses on NumPy. à Provides multidimensional array object which stores homogeneous or heterogeneous data arrays.
  • It also Supports code vectorization.

Arrays of Data

  • Python has useful and flexible general data structures, like lists.
  • Lists can have higher memory usage and slower performance.
  • Scientific and financial applications require high-performing operations on special data structures, like arrays.
  • Arrays structure objects of the same data type in rows and columns.
  • One-dimensional arrays represent vectors, while multidimensional arrays can represent matrices, cubes, or n-dimensional shapes.

Arrays with Python Lists

  • Arrays can be built using built-in data structures.
  • List objects are well-suited for this purpose.
  • A simple list can represent a one-dimensional array.
  • Since list objects can contain arbitrary other objects à they can also contain other list object and can be used to construct two- and higher-dimensional arrays

Arrays with Python Lists

  • Accessing the matrix elements
  • Nesting can be pushed further for even more general structures:

The Python array Class

  • Consider the following code, which instantiates an array object out of a list object:

The Python array Class

  • Trying to append an object of different data type than the one specified raises a TypeError:

The Python array Class

  • The data type of the array object is of importance when reading the data from disk:

Regular Numpy Arrays

  • List objects can be used for composing array structures.
  • Lists are not specifically designed for this purpose.
  • List class has a broader and more general scope.
  • Array class is more specialized for working with arrays of data.
  • A truly specialized class could greatly benefit array-type structures handling.
  • numpy.ndarray is such a class, built with the specific goal of handling dimensional arrays both conveniently and efficiently, i.e. in a highly performance manner

Regular Numpy Arrays

  • A major feature of the ndarray class is the multitude of built-in methods:

Regular Numpy Arrays

  • Another major feature is the (vectorized) mathematical operations defined on ndarray objects:

Regular Numpy Arrays

  • Universal functions are another important feature of the Numpy Package
  • Operate on ndarray objects and basic Python data types.
  • Applicable to Python float objects, but with reduced performance.
  • Performance advantage when using math module for basic Python data types.

Regular Numpy Arrays

  • Cont..

Multiple Dimensions

  • Cont.

Multiple Dimensions

  • Multiple ways to initialize ndarray objects.
  • np.array used when all elements are available.
  • Alternative approach: instantiate ndarray first.
  • Populate ndarray later with results from code execution.