1 / 16

Lesson 21 NumPy

Lesson 21 NumPy. Python Mini-Course University of Oklahoma Department of Psychology . Lesson objectives. Use the NumPy package. What is NumPy?. NumPy is the fundamental package needed for scientific computing with Python. It contains: a powerful N-dimensional array object

jersey
Télécharger la présentation

Lesson 21 NumPy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lesson 21NumPy Python Mini-Course University of Oklahoma Department of Psychology Python Mini-Course: Lesson 21

  2. Lesson objectives • Use the NumPy package Python Mini-Course: Lesson 21

  3. What is NumPy? • NumPy is the fundamental package needed for scientific computing with Python. It contains: • a powerful N-dimensional array object • basic linear algebra functions • basic Fourier transforms • sophisticated random number capabilities • tools for integrating Fortran code • tools for integrating C/C++ code Python Mini-Course: Lesson 21

  4. NumPy documentation • Official documentation • http://docs.scipy.org/doc/ • The NumPy book • http://www.tramy.us/numpybook.pdf • Example list • http://www.scipy.org/Numpy_Example_List_With_Doc Python Mini-Course: Lesson 21

  5. The ndarray data structure • NumPy adds a new data structure to Python – the ndarray • An N-dimensional array is a homogeneous collection of “items” indexed using N integers • Defined by: • the shape of the array, and • the kind of item the array is composed of Python Mini-Course: Lesson 21

  6. Array shape • ndarrays are rectangular • The shape of the array is a tuple of N integers (one for each dimension) Python Mini-Course: Lesson 21

  7. Array item types • Every ndarray is a homogeneous collection of exactly the same data-type • every item takes up the same size block of memory • each block of memory in the array is interpreted in exactly the same way Python Mini-Course: Lesson 21

  8. Python Mini-Course: Lesson 21

  9. Python Mini-Course: Lesson 21

  10. Example: creating an array import numpy a = array([[1,2,3], [4,5,6], [7,8,9]]) a.shape a.dtype Python Mini-Course: Lesson 21

  11. Indexing arrays • Use a tuple to index multi-dimensional arrays • Example: a[1,2] Python Mini-Course: Lesson 21

  12. Slicing arrays • Slicing arrays is almost the same as slicing lists, except you can specify multiple dimensions Python Mini-Course: Lesson 21

  13. Examples: Slicing arrays a[1] a[1,:] a[1,1:] a[:1,1:] Python Mini-Course: Lesson 21

  14. Some ndarray methods • ndarray. tolist () • The contents of self as a nested list • ndarray. copy () • Return a copy of the array • ndarray. fill (scalar) • Fill an array with the scalar value Python Mini-Course: Lesson 21

  15. Some NumPy functions abs() add() binomial() cumprod() cumsum() floor() histogram() min() max() multipy() polyfit() randint() shuffle() transpose() Python Mini-Course: Lesson 21

  16. Suggested exercise • Complete the desc_stat_calc.py program Python Mini-Course: Lesson 21

More Related