Section 9: Introduction to NumPy and SciPy
Section 9: Introduction to NumPy and SciPy
Linxing Preston Jiang
Allen School of Computer Science & Engineering, University of Washington
May 24, 2018
Introduction
Numpy
SciPy
1
Motivation
We have learned all basic data structures...do we need more?
Introduction
Numpy
SciPy
2
A question
You have an matrix like this:
1 2 3 4
4 5 6
7
7 8 9 10
and you want to sum up numbers by each column. How do you write code for it?
Introduction
Numpy
SciPy
3
In Python
a solution using native list
sums = [] for col_idx in range(len(matrix [0])):
sum = 0 for row_idx in range(len(matrix)):
sum += matrix[row_idx][col_idx] sums.append(sum) print sums
Introduction
Numpy
SciPy
4
In Python
a solution if using numpy arrays
print matrix.sum(axis=1)
Introduction
Numpy
SciPy
5
Another comparison
Sum benchmark: summing over a list
from numpy import arange import time
N = 10000000 numpy_array = arange(N) python_list = range(N) print "### python list ###" start = time.time() sum = 0 for i in python_list:
sum += i print "average is: ", float(sum) / N print "used time: ", time.time() - start print "### numpy array ###" start = time.time() print "average is: ", numpy_array.mean() print "used time: ", time.time() - start
Introduction
Numpy
SciPy
6
First, import
import numpy OR
import numpy as np (assuming this from now on)
Introduction
Numpy
SciPy
7
Most important module of NumPy: Arrays
just like lists, but could only contain same type of objects!
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- section 9 introduction to numpy and scipy
- introduction to numpy arrays github
- numpy cbse board array
- numpy arrays marquette university
- python numpy cheat sheet intellipaat
- using the global arrays toolkit to reimplement numpy for
- working with multidimensional scientific data using python
- numpy primer cornell university
- numpy tutorialspoint
Related searches
- wyoming section 9 map
- introduction to finance and accounting
- introduction to leadership and management
- introduction to java programming and data structures
- introduction to language and linguistics
- introduction to leadership and governance
- introduction to philosophy and logic
- introduction to positive and negative numbers
- introduction to leadership concepts and practice
- introduction to food and beverage service
- introduction to probability and mathematical statistics pdf
- chapter 9 introduction to waves