-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths06_numpy.py
More file actions
123 lines (82 loc) · 2.8 KB
/
s06_numpy.py
File metadata and controls
123 lines (82 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
"""S06 - numpy.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1edCbvvTIReVihWAJIS_7VP0sOCYI45Wp
## numpy
NumPy (pronounced /ˈnʌmpaɪ/ (NUM-py) or sometimes /ˈnʌmpi/ (NUM-pee)) is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.
## scipy
SciPy (pronounced /ˈsaɪpaɪ/ "sigh pie") is a free and open-source Python library used for scientific computing and technical computing.
* `cluster`: hierarchical clustering, vector quantization, K-means
* `constants`: physical constants and conversion factors
* `fft`: Discrete Fourier Transform algorithms
* `fftpack`: Legacy interface for Discrete Fourier Transforms
* `integrate`: numerical integration routines
interpolate: interpolation tools
* `io`: data input and output
* `linalg`: linear algebra routines
* `misc`: miscellaneous utilities (e.g. example images)
* `ndimage`: various functions for multi-dimensional image processing
* `ODR`: orthogonal distance regression classes and algorithms
* `optimize`: optimization algorithms including linear programming
* `signal`: signal processing tools
* `sparse`: sparse matrices and related algorithms
* `spatial`: algorithms for spatial structures such as k-d trees, nearest neighbors, Convex hulls, etc.
* `special`: special functions
* `stats`: statistical functions
"""
# Why native python lists are not what we want!
a = [1, 2, 3, 5]
b = 4
print(b*a)
import numpy as np
a = np.arange(6)
print(a)
type(a)
b = np.array([1, 2, 3, 4, 5, 6])
print(b)
print(3*b)
print(b * 9 / 5 + 32)
print(a[0])
"""**Arrays of higher dimensions**"""
# more than one dimension
i = np.array(10)
j = np.array([1,2,5,6,8])
k = np.array([[1,2,5,6,8], [4,10,5,9,12]])
l = np.array([[[3,4],[5,6]],[[34,43],[12,11]]])
print(i.ndim)
print(j.ndim)
print(k.ndim)
print(l.ndim)
print(i.size)
"""**Indedxing `numpy` arrays**"""
a = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
print(a[1])
print(a[1,2])
print(a)
np.empty(2)
x = np.arange(0,10,2)
y = np.linspace(0,8,5)
print(x,y)
print(np.linspace(2,3,100,endpoint=False))
np.concatenate((x,y))
x = np.array([[1, 2], [3, 4]])
y = np.array([[5, 6], [7, 8]])
print(x)
print(y)
print(np.concatenate((x, y), axis=0)) # rbind
print(np.concatenate((x, y), axis=1)) # cbind
z =array_example = np.array([[[0, 1, 2, 3],
[4, 5, 6, 7]],
[[0, 1, 2, 3],
[4, 5, 6, 7]],
[[0 ,1 ,2, 3],
[4, 5, 6, 7]]])
print(z)
z.ndim
z.mean()
np.mean(z)
z.shape[1]
for i in range(0,z.shape[0]):
print(z[i,:,:], "\n**\n**\n")
print(z)