-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode11_array_oper.py
More file actions
50 lines (34 loc) · 1.05 KB
/
Copy pathcode11_array_oper.py
File metadata and controls
50 lines (34 loc) · 1.05 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
"""
1.4.5 大型数组运算
"""
x = [1, 2, 3, 4]
y = [5, 6, 7, 8]
print(f'{x} * 2 is: {x * 2}')
# print(x + 10)
print(f'{x} + {y} = {x + y}')
import numpy as np
ax = np.array([1, 2, 3, 4])
ay = np.array([5, 6, 7, 8])
print(f'{ax} * 2 = {ax * 2}')
print(f'{ax} + 10 = {ax + 10}')
print(f'{ax} + {ay} = {ax + ay}')
print(f'{ax} * {ay} = {ax * ay}')
def f(px):
return 3 * px ** 2 - 2 * px + 7
print(f'f(ax) = {f(ax)}')
print(f'np.sqrt({ax}) = {np.sqrt(ax)}')
print(f'np.cos({ax}) = {np.cos(ax)}')
grid = np.zeros(shape=(10000,10000), dtype=float)
print(f'np.zeros(shape=(10000,10000), dtype=float) result: \n{grid}')
grid += 10
print(f'grid + 10 result:\n{grid}')
print(f'np.sin(grid) result:\n{np.sin(grid)}')
a = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
print(f'a is:\n{a}')
print(f'a[1] is:\n{a[1]}')
print(f'a[:,1] is:\n{a[:,1]}')
print(f'a[1:3, 1:3] is:\n{a[1:3, 1:3]}')
a[1:3, 1:3] += 10
print(f'a is:\n{a}')
print(f'a + [100, 101, 102, 103] is:\n{a + [100, 101, 102, 103]}')
print(f'np.where(a < 10, a, 10) is:\n{np.where(a < 10, a, 10)}')