NumPy and Matplotlib

[Pages:26]NumPy and Matplotlib



Computer Science, CMU 204101 Introduction to Computer

1

Overview

NumPy (Numeric Python) Python (Array)

NumPy commercial software MatLab

NumPy Vector and matrix mathematics

Computer Science, CMU 204101 Introduction to Computer

2

Import NumPy module

import NumPy

import numpy

NumPy numpy.X np import

import numpy as np np.X

Computer Science, CMU 204101 Introduction to Computer

3

Arrays

Arrays NumPy list array int float

Arrays list

Array Vectors Matrices

Computer Science, CMU 204101 Introduction to Computer

4

Vector and Matrix

Vector

1

=

2 ...

1 -2

,

0.6 -4 9

Matrix

11 1

A=

1

1 3

2 4

Computer Science, CMU 204101 Introduction to Computer

5

array

Vector Matrix Array

Array list

import numpy as np

a = np.array([1,2,4,8],float) print(a)

[ 1. 2. 4. 8.]

type(a)

Array 1 Vector

Computer Science, CMU 204101 Introduction to Computer

6

array

array 2

list array array

array list

import numpy as np

a = np.array([1,2,4,8], float)

print(a[3])

8.0

a[0] = 5

print(a)

[ 5. 2. 4. 8.]

Computer Science, CMU 204101 Introduction to Computer

7

array

Array list comma

Array 2 Matrix

import numpy as np

a = np.array([[1,2,3],[4,5,6]],float)

print(a)

[[ 1. 2. 3.] [ 4. 5. 6.]]

print(a[0,0])

1.0

print(a[0,1])

2.0

Computer Science, CMU 204101 Introduction to Computer

8

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download