-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0002. NumPy.
More file actions
56 lines (40 loc) · 942 Bytes
/
0002. NumPy.
File metadata and controls
56 lines (40 loc) · 942 Bytes
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
import numpy as np
from numpy import random
arr = np.array([1, 2, 3, 4, 5])
print(arr)
print(type(arr))
print(np.__version__)
print(arr.ndim)
arr = np.array([1, 2, 3, 4, 5], ndmin=5)
print(arr)
print("Number of dimensions:", arr.ndim)
arr = np.array([1.1, 2.9, 3.5])
new_arr = arr.astype("i")
print(new_arr)
print(new_arr.dtype)
arr = np.array([1, 2, 3, 4, 5])
print(arr.shape)
x = random.randint(100)
print(x)
x = random.rand()
print(x)
x = random.randint(100, size=5)
print(x)
x = random.randint(100, size=(3, 5))
print(x)
x = random.rand(5)
print(x)
x = random.rand(3, 5)
print(x)
x = random.choice([3, 5, 7, 9])
print(x)
x = random.choice([3, 5, 7, 9], size=(3, 5))
print(x)
x = random.choice([3, 5, 7, 9], p=[0.1, 0.3, 0.6, 0.0], size=111)
print(x)
x = random.choice([3, 5, 7, 9], p=[0.1, 0.3, 0.6, 0.0], size=(3, 5))
print(x)
arr = np.array([1, 2, 3, 4, 5])
random.shuffle(arr)
print(arr)
print(random.permutation(arr))